use of com.axelor.apps.project.db.Wiki in project axelor-open-suite by axelor.
the class ProjectServiceImpl method createProjectFromTemplate.
@Override
@Transactional
public Project createProjectFromTemplate(ProjectTemplate projectTemplate, String projectCode, Partner clientPartner) throws AxelorException {
Project project = new Project();
project.setName(projectTemplate.getName());
if (projectRepository.all().filter("self.code = ?", projectCode).count() > 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, ITranslation.PROJECT_CODE_ERROR);
} else {
project.setCode(projectCode);
project.setClientPartner(clientPartner);
if (clientPartner != null && clientPartner.getContactPartnerSet() != null && !clientPartner.getContactPartnerSet().isEmpty()) {
project.setContactPartner(clientPartner.getContactPartnerSet().iterator().next());
}
project.setDescription(projectTemplate.getDescription());
project.setTeam(projectTemplate.getTeam());
project.setProjectFolderSet(new HashSet<>(projectTemplate.getProjectFolderSet()));
project.setAssignedTo(projectTemplate.getAssignedTo());
project.setProjectTaskCategorySet(new HashSet<>(projectTemplate.getProjectTaskCategorySet()));
project.setSynchronize(projectTemplate.getSynchronize());
project.setMembersUserSet(new HashSet<>(projectTemplate.getMembersUserSet()));
project.setImputable(projectTemplate.getImputable());
project.setCompany(projectTemplate.getCompany());
project.setProductSet(new HashSet<>(projectTemplate.getProductSet()));
project.setExcludePlanning(projectTemplate.getExcludePlanning());
project.setProjectTypeSelect(ProjectRepository.TYPE_PROJECT);
List<Wiki> wikiList = projectTemplate.getWikiList();
if (wikiList != null && !wikiList.isEmpty()) {
for (Wiki wiki : wikiList) {
wiki = wikiRepo.copy(wiki, false);
wiki.setProjectTemplate(null);
project.addWikiListItem(wiki);
}
}
projectRepository.save(project);
Set<TaskTemplate> taskTemplateSet = projectTemplate.getTaskTemplateSet();
if (ObjectUtils.isEmpty(taskTemplateSet)) {
return project;
}
List<TaskTemplate> taskTemplateList = new ArrayList<TaskTemplate>(taskTemplateSet);
Collections.sort(taskTemplateList, new Comparator<TaskTemplate>() {
@Override
public int compare(TaskTemplate taskTemplatet1, TaskTemplate taskTemplate2) {
return taskTemplatet1.getParentTaskTemplate() == null || taskTemplate2 == null ? 1 : taskTemplatet1.getParentTaskTemplate().equals(taskTemplate2) ? -1 : 1;
}
});
if (taskTemplateList != null) {
for (TaskTemplate taskTemplate : taskTemplateList) {
createTask(taskTemplate, project, taskTemplateSet);
}
}
return project;
}
}
Aggregations