use of org.collectiveone.modules.governance.Governance in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method create.
@Transactional
private GetResult<Initiative> create(UUID c1Id, NewInitiativeDto initiativeDto) {
AppUser creator = appUserRepository.findByC1Id(c1Id);
if (creator == null) {
return new GetResult<Initiative>("error", "creator not found", null);
}
Initiative initiative = new Initiative();
/* Basic properties*/
initiative.setCreator(creator);
initiative.setStatus(InitiativeStatus.ENABLED);
InitiativeMeta meta = new InitiativeMeta();
meta.setName(initiativeDto.getName());
meta.setDriver(initiativeDto.getDriver());
meta.setCreationDate(new Timestamp(System.currentTimeMillis()));
meta.setModelEnabled(true);
if (!initiativeDto.getAsSubinitiative()) {
meta.setColor("#009ee3");
} else {
Initiative parent = initiativeRepository.findById(UUID.fromString(initiativeDto.getParentInitiativeId()));
meta.setColor(parent.getMeta().getColor());
}
meta = initiativeMetaRepository.save(meta);
initiative.setMeta(meta);
initiative = initiativeRepository.save(initiative);
/* Create the governace object of this initiative */
Governance governance = governanceService.create(initiative);
initiative.setGovernance(governance);
initiative = initiativeRepository.save(initiative);
activityService.newInitiativeCreated(initiative, initiative.getCreator());
return new GetResult<Initiative>("success", "initiative created", initiative);
}
Aggregations