Search in sources :

Example 1 with Governance

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);
}
Also used : GetResult(org.collectiveone.common.dto.GetResult) AppUser(org.collectiveone.modules.users.AppUser) Governance(org.collectiveone.modules.governance.Governance) Timestamp(java.sql.Timestamp) Transactional(javax.transaction.Transactional)

Aggregations

Timestamp (java.sql.Timestamp)1 Transactional (javax.transaction.Transactional)1 GetResult (org.collectiveone.common.dto.GetResult)1 Governance (org.collectiveone.modules.governance.Governance)1 AppUser (org.collectiveone.modules.users.AppUser)1