Skip to content
Snippets Groups Projects

Adjustments to MVP ICSHWI-9916

Merged Zoltan Runyo requested to merge adjustments-to-mvp-ICSHWI-9916 into develop
Files
39
package eu.ess.ics.ce.template.common.conversion;
import eu.ess.ics.ce.template.repository.entity.IocInstanceEntity;
import eu.ess.ics.ce.template.repository.entity.TemplateEntity;
import eu.ess.ics.ce.template.rest.controller.TemplateController;
import eu.ess.ics.ce.template.rest.model.iocinstance.response.IocInstance;
import eu.ess.ics.ce.template.rest.model.template.response.Template;
import eu.ess.ics.ce.template.service.external.gitlab.GitLabService;
import org.gitlab4j.api.GitLabApiException;
import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author <a href="mailto:zoltan.runyo@ess.eu">Zoltan Runyo</a>
**/
public class ConversionUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ConversionUtil.class);
public static Template convert(GitLabService gitLabService, TemplateEntity templateEntity) {
Project templateProject = null;
try {
templateProject = gitLabService.projectFromId(templateEntity.getGitProjectId());
} catch (GitLabApiException e) {
LOGGER.error("Cannot find gitlab project by ID: " + templateEntity.getGitProjectId(), e);
}
Project configProject = null;
try {
configProject = gitLabService.projectFromId(templateEntity.getConfiguration().getGitProjectId());
} catch (GitLabApiException e) {
LOGGER.error("Cannot find gitlab project by ID: " + templateEntity.getConfiguration().getGitProjectId(), e);
}
return new Template(
templateEntity.getId(),
templateProject != null ? templateProject.getName() : templateEntity.getName(),
templateProject != null ? templateProject.getId() : templateEntity.getGitProjectId(),
templateProject != null ? templateProject.getWebUrl() : null,
configProject != null ? configProject.getId() : templateEntity.getConfiguration().getGitProjectId(),
configProject != null ? configProject.getWebUrl() : null,
templateEntity.getOwner(),
templateEntity.getCreatedAt());
}
public static IocInstance convert(GitLabService gitLabService, IocInstanceEntity iocInstanceEntity) {
Project templateProject = null;
try {
templateProject = gitLabService.projectFromId(iocInstanceEntity.getTemplateGitProjectId());
} catch (GitLabApiException e) {
LOGGER.error("Cannot find gitlab project by ID: " + iocInstanceEntity.getTemplateGitProjectId(), e);
}
Project gitProject = null;
Commit commit = null;
try {
gitProject = gitLabService.projectFromId(iocInstanceEntity.getGitProjectId());
commit = gitLabService.getCommit(gitProject.getId(), iocInstanceEntity.getGitRevision());
} catch (GitLabApiException e) {
LOGGER.error("Cannot find gitlab project by ID: " + iocInstanceEntity.getGitProjectId(), e);
}
return new IocInstance(
iocInstanceEntity.getId(),
templateProject != null ? templateProject.getId() : iocInstanceEntity.getTemplateGitProjectId(),
// TODO Discuss which name must be retrieved: stored or actual from Git
// (decision may affect template search as well!)
//templateProject != null ? templateProject.getName() : null,
iocInstanceEntity.getTemplate().getName(),
iocInstanceEntity.getCreatedBy(),
iocInstanceEntity.getCreatedAt(),
gitProject != null ? gitProject.getId() : iocInstanceEntity.getGitProjectId(),
gitProject != null ? gitProject.getWebUrl() : null,
iocInstanceEntity.getGitRevision(),
commit != null ? commit.getShortId() : null);
}
}
Loading