Search in sources :

Example 31 with PostResult

use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method deleteMember.

public PostResult deleteMember(UUID initiativeId, UUID memberUserId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    Member member = memberRepository.findByInitiative_IdAndUser_C1Id(initiativeId, memberUserId);
    List<DecisionMaker> admins = governanceService.getDecisionMakerWithRole(initiative.getGovernance().getId(), DecisionMakerRole.ADMIN);
    boolean otherAdmin = false;
    for (DecisionMaker admin : admins) {
        if (!admin.getUser().getC1Id().equals(memberUserId)) {
            otherAdmin = true;
        }
    }
    if (otherAdmin) {
        /* delete only if another admin remains */
        /* members were subscribed to initiatives by default, so, delete them when deleting the member */
        activityService.removeSubscriber(initiativeId, member.getUser().getC1Id());
        memberRepository.delete(member);
        governanceService.deleteDecisionMaker(initiative.getGovernance().getId(), member.getUser().getC1Id());
        return new PostResult("success", "contributor deleted", "");
    }
    return new PostResult("error", "user is the only admin, it cannot be deleted", "");
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker)

Example 32 with PostResult

use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method addTagToInitiative.

@Transactional
public PostResult addTagToInitiative(UUID initiativeId, InitiativeTagDto tagDto) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    if (initiative == null)
        return new PostResult("error", "initiative not found", "");
    InitiativeTag tag = getOrCreateTag(tagDto);
    initiative.getMeta().getTags().add(tag);
    return new PostResult("success", "tag added to initiative", tag.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) Transactional(javax.transaction.Transactional)

Example 33 with PostResult

use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method edit.

@Transactional
public PostResult edit(UUID initiativeId, UUID userId, NewInitiativeDto initiativeDto) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    InitiativeMeta initiativeMeta = initiative.getMeta();
    String oldName = initiativeMeta.getName();
    String oldDriver = initiativeMeta.getDriver();
    initiativeMeta.setName(initiativeDto.getName());
    initiativeMeta.setDriver(initiativeDto.getDriver());
    initiativeMeta.setColor(initiativeDto.getColor());
    initiativeMeta.setModelEnabled(initiativeDto.getModelEnabled());
    if (initiativeDto.getVisibility() != null) {
        initiativeMeta.setVisibility(InitiativeVisibility.valueOf(initiativeDto.getVisibility()));
    }
    /* remove and add all tags */
    initiativeMeta.getTags().removeAll(initiativeMeta.getTags());
    for (InitiativeTagDto tagDto : initiativeDto.getTags()) {
        InitiativeTag tag = initiativeTagRepository.findById(UUID.fromString(tagDto.getId()));
        initiativeMeta.getTags().add(tag);
    }
    /* update or remove image */
    if (initiativeDto.getNewImageFileId() != null) {
        if (!initiativeDto.getNewImageFileId().equals("REMOVE")) {
            UUID imageFileId = initiativeDto.getNewImageFileId().equals("") ? null : UUID.fromString(initiativeDto.getNewImageFileId());
            FileStored imageFile = fileStoredRepository.findById(imageFileId);
            initiativeMeta.setImageFile(imageFile);
        } else {
            initiativeMeta.setImageFile(null);
        }
    }
    initiativeMetaRepository.save(initiativeMeta);
    if (!oldName.equals(initiativeDto.getName()) || !oldDriver.equals(initiativeDto.getDriver())) {
        /* notify only if actually different */
        activityService.initiativeEdited(initiative, appUserRepository.findByC1Id(userId), oldName, oldDriver);
    }
    return new PostResult("success", "initaitive updated", initiative.getId().toString());
}
Also used : InitiativeTagDto(org.collectiveone.modules.initiatives.dto.InitiativeTagDto) PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) FileStored(org.collectiveone.modules.files.FileStored) Transactional(javax.transaction.Transactional)

Example 34 with PostResult

use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method transferAssets.

@Transactional
private PostResult transferAssets(UUID initiativeId, NewInitiativeDto initiativeDto, UUID creatorId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    if (!initiativeDto.getAsSubinitiative()) {
        /* if is not a sub-initiative, then create a token for this initiative */
        if (initiativeDto.getCreateToken()) {
            TokenType token = tokenService.create(initiativeDto.getOwnTokens().getAssetName(), "T");
            initiative.getTokenTypes().add(token);
            initiative = initiativeRepository.save(initiative);
            tokenService.mintToHolder(token.getId(), initiative.getId(), initiativeDto.getOwnTokens().getOwnedByThisHolder(), TokenHolderType.INITIATIVE);
            TokenMint mint = new TokenMint();
            mint.setToken(token);
            mint.setOrderedBy(appUserRepository.findByC1Id(creatorId));
            mint.setToHolder(initiativeId);
            mint.setMotive("Initiative creation.");
            mint.setNotes("");
            mint.setValue(initiativeDto.getOwnTokens().getOwnedByThisHolder());
            mint = tokenMintRespository.save(mint);
        }
        return new PostResult("success", "initiative tokens created", initiative.getId().toString());
    } else {
        Initiative parent = initiativeRepository.findById(UUID.fromString(initiativeDto.getParentInitiativeId()));
        /* if it is a sub-initiative, then link to parent initiative */
        InitiativeRelationship relationship = new InitiativeRelationship();
        relationship.setInitiative(initiative);
        relationship.setType(InitiativeRelationshipType.IS_ATTACHED_SUB);
        relationship.setOfInitiative(parent);
        relationship = initiativeRelationshipRepository.save(relationship);
        List<InitiativeTransfer> transfers = new ArrayList<InitiativeTransfer>();
        /* and transfer parent assets to child */
        for (TransferDto thisTransfer : initiativeDto.getAssetsTransfers()) {
            /* ignore zero token transfers */
            if (thisTransfer.getValue() > 0) {
                TokenType token = tokenService.getTokenType(UUID.fromString(thisTransfer.getAssetId()));
                tokenService.transfer(token.getId(), parent.getId(), initiative.getId(), thisTransfer.getValue(), TokenHolderType.INITIATIVE);
                /* upper layer keeping track of who transfered what to whom */
                InitiativeTransfer transfer = new InitiativeTransfer();
                transfer.setFrom(parent);
                transfer.setTo(initiative);
                transfer.setTokenType(token);
                transfer.setValue(thisTransfer.getValue());
                transfer.setMotive("sub-initiative creation");
                transfer.setNotes("");
                transfer.setOrderDate(new Timestamp(System.currentTimeMillis()));
                transfer = initiativeTransferRepository.save(transfer);
                transfers.add(transfer);
            }
        }
        initiative.getRelationships().add(relationship);
        initiativeRepository.save(initiative);
        activityService.newSubinitiativeCreated(parent, initiative.getCreator(), initiative, transfers);
    }
    return new PostResult("success", "sub initiative created and tokens transferred", initiative.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) TokenType(org.collectiveone.modules.tokens.TokenType) TokenMint(org.collectiveone.modules.tokens.TokenMint) ArrayList(java.util.ArrayList) TransferDto(org.collectiveone.modules.tokens.dto.TransferDto) InitiativeTransfer(org.collectiveone.modules.tokens.InitiativeTransfer) Timestamp(java.sql.Timestamp) Transactional(javax.transaction.Transactional)

Example 35 with PostResult

use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method createNewToken.

@Transactional
public PostResult createNewToken(UUID initiativeId, AssetsDto tokenDto, UUID userId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    TokenType token = tokenService.create(tokenDto.getAssetName(), "T");
    initiative.getTokenTypes().add(token);
    initiative = initiativeRepository.save(initiative);
    tokenService.mintToHolder(token.getId(), initiative.getId(), tokenDto.getOwnedByThisHolder(), TokenHolderType.INITIATIVE);
    AppUser orderedBy = appUserRepository.findByC1Id(userId);
    TokenMint mint = new TokenMint();
    mint.setToken(token);
    mint.setOrderedBy(orderedBy);
    mint.setToHolder(initiativeId);
    mint.setMotive("Token creation.");
    mint.setNotes("");
    mint.setValue(tokenDto.getOwnedByThisHolder());
    mint = tokenMintRespository.save(mint);
    activityService.newTokenCreated(initiative, orderedBy, token, mint);
    return new PostResult("success", "initiative created and tokens created", initiative.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) TokenType(org.collectiveone.modules.tokens.TokenType) TokenMint(org.collectiveone.modules.tokens.TokenMint) AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Aggregations

PostResult (org.collectiveone.common.dto.PostResult)47 Transactional (javax.transaction.Transactional)28 UUID (java.util.UUID)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 Initiative (org.collectiveone.modules.initiatives.Initiative)11 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)7 DecisionVerdict (org.collectiveone.modules.governance.DecisionVerdict)5 AppUser (org.collectiveone.modules.users.AppUser)5 Timestamp (java.sql.Timestamp)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 FileStored (org.collectiveone.modules.files.FileStored)3 TokenType (org.collectiveone.modules.tokens.TokenType)3 DecisionMaker (org.collectiveone.modules.governance.DecisionMaker)2 ModelSectionDto (org.collectiveone.modules.model.dto.ModelSectionDto)2 TokenMint (org.collectiveone.modules.tokens.TokenMint)2 ArrayList (java.util.ArrayList)1 WantToContributeNotification (org.collectiveone.modules.activity.WantToContributeNotification)1 BillDto (org.collectiveone.modules.assignations.dto.BillDto)1 EvaluationGradeDto (org.collectiveone.modules.assignations.dto.EvaluationGradeDto)1