Search in sources :

Example 6 with Initiative

use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method createView.

@Transactional
public PostResult createView(UUID initiativeId, ModelViewDto viewDto, UUID creatorId, boolean register) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    if (initiative == null)
        return new PostResult("error", "initiative not found", "");
    ModelView view = viewDto.toEntity(null, viewDto, initiative);
    view = modelViewRepository.save(view);
    initiative.getModelViews().add(view);
    initiativeRepository.save(initiative);
    if (register)
        activityService.modelViewCreated(view, appUserRepository.findByC1Id(creatorId));
    return new PostResult("success", "view created", view.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) Initiative(org.collectiveone.modules.initiatives.Initiative) Transactional(javax.transaction.Transactional)

Example 7 with Initiative

use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method moveView.

@Transactional
public PostResult moveView(UUID initiativeId, UUID viewId, UUID onViewId, UUID creatorId) {
    if (onViewId.equals(viewId)) {
        return new PostResult("warning", "cannot move on itself", null);
    }
    Initiative initiative = initiativeRepository.findById(initiativeId);
    ModelView view = modelViewRepository.findById(viewId);
    ModelView beforeView = modelViewRepository.findById(onViewId);
    int index = initiative.getModelViews().indexOf(beforeView);
    initiative.getModelViews().remove(view);
    initiativeRepository.save(initiative);
    initiative.getModelViews().add(index, view);
    activityService.modelViewMoved(view, appUserRepository.findByC1Id(creatorId));
    modelViewRepository.save(view);
    initiativeRepository.save(initiative);
    return new PostResult("success", "view moved", view.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) Initiative(org.collectiveone.modules.initiatives.Initiative) Transactional(javax.transaction.Transactional)

Example 8 with Initiative

use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method editView.

@Transactional
public PostResult editView(UUID initiativeId, UUID viewId, ModelViewDto viewDto, UUID creatorId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    if (initiative == null)
        return new PostResult("error", "initiative not found", "");
    ModelView view = modelViewRepository.findById(viewId);
    view = viewDto.toEntity(view, viewDto, initiative);
    view = modelViewRepository.save(view);
    activityService.modelViewEdited(view, appUserRepository.findByC1Id(creatorId));
    return new PostResult("success", "view edited", view.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) Initiative(org.collectiveone.modules.initiatives.Initiative) Transactional(javax.transaction.Transactional)

Example 9 with Initiative

use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.

the class TokenTransferService method getTransferredToSubinitiatives.

/**
 * Get the tokens transferred from one initiative into its sub-initiatives
 */
@Transactional
public List<TransferDto> getTransferredToSubinitiatives(UUID tokenId, UUID initiativeId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    TokenType token = tokenService.getTokenType(tokenId);
    /* get of sub-initiatives */
    List<InitiativeRelationship> subinitiativesRelationships = initiativeRelationshipRepository.findByOfInitiativeIdAndInitiative_StatusAndType(initiative.getId(), InitiativeStatus.ENABLED, InitiativeRelationshipType.IS_ATTACHED_SUB);
    List<TransferDto> transferredToSubinitiatives = new ArrayList<TransferDto>();
    for (InitiativeRelationship relationship : subinitiativesRelationships) {
        /* get all transfers of a given token made from and to these initiatives */
        Double totalTransferred = initiativeTransferRepository.getTotalTransferredFromTo(tokenId, relationship.getOfInitiative().getId(), relationship.getInitiative().getId());
        Double totalReturned = initiativeTransferRepository.getTotalTransferredFromTo(tokenId, relationship.getInitiative().getId(), relationship.getOfInitiative().getId());
        TransferDto dto = new TransferDto();
        dto.setAssetId(token.getId().toString());
        dto.setAssetName(token.getName());
        dto.setSenderId(relationship.getOfInitiative().getId().toString());
        dto.setSenderName(relationship.getOfInitiative().getMeta().getName());
        dto.setReceiverId(relationship.getInitiative().getId().toString());
        dto.setReceiverName(relationship.getInitiative().getMeta().getName());
        dto.setValue(totalTransferred - totalReturned);
        transferredToSubinitiatives.add(dto);
    }
    return transferredToSubinitiatives;
}
Also used : InitiativeRelationship(org.collectiveone.modules.initiatives.InitiativeRelationship) ArrayList(java.util.ArrayList) TransferDto(org.collectiveone.modules.tokens.dto.TransferDto) Initiative(org.collectiveone.modules.initiatives.Initiative) Transactional(javax.transaction.Transactional)

Example 10 with Initiative

use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.

the class TokenTransferService method transferFromInitiativeToInitiative.

@Transactional
public PostResult transferFromInitiativeToInitiative(UUID fromInitiativeId, UUID toInitiativeId, UUID orderByUserId, UUID assetId, double value, String motive, String notes) {
    TokenType tokenType = tokenService.getTokenType(assetId);
    Initiative from = initiativeRepository.findById(fromInitiativeId);
    Initiative to = initiativeRepository.findById(toInitiativeId);
    String result = tokenService.transfer(tokenType.getId(), from.getId(), to.getId(), value, TokenHolderType.INITIATIVE);
    if (result.equals("success")) {
        /* register the transfer to the initiative  */
        InitiativeTransfer transfer = new InitiativeTransfer();
        transfer.setTokenType(tokenType);
        transfer.setFrom(from);
        transfer.setTo(to);
        transfer.setMotive(motive);
        transfer.setNotes(notes);
        transfer.setValue(value);
        transfer.setOrderDate(new Timestamp(System.currentTimeMillis()));
        transfer.setOrderedBy(appUserRepository.findByC1Id(orderByUserId));
        transfer = initiativeTransferRepository.save(transfer);
        activityService.transferToSubinitiative(transfer);
        return new PostResult("success", "transfer done", transfer.getId().toString());
    } else {
        return new PostResult("success", "error making the transfer:" + result, "");
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) Initiative(org.collectiveone.modules.initiatives.Initiative) Timestamp(java.sql.Timestamp) Transactional(javax.transaction.Transactional)

Aggregations

Initiative (org.collectiveone.modules.initiatives.Initiative)32 Transactional (javax.transaction.Transactional)15 UUID (java.util.UUID)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 PostResult (org.collectiveone.common.dto.PostResult)11 GetResult (org.collectiveone.common.dto.GetResult)10 ArrayList (java.util.ArrayList)4 TransferDto (org.collectiveone.modules.tokens.dto.TransferDto)4 ActivityDto (org.collectiveone.modules.activity.dto.ActivityDto)3 PageRequest (org.springframework.data.domain.PageRequest)3 Email (com.sendgrid.Email)2 Personalization (com.sendgrid.Personalization)2 Timestamp (java.sql.Timestamp)2 Assignation (org.collectiveone.modules.assignations.Assignation)2 ModelCardWrapper (org.collectiveone.modules.model.ModelCardWrapper)2 ModelSection (org.collectiveone.modules.model.ModelSection)2 ModelView (org.collectiveone.modules.model.ModelView)2 TokenMint (org.collectiveone.modules.tokens.TokenMint)2 TokenType (org.collectiveone.modules.tokens.TokenType)2 AssetsDto (org.collectiveone.modules.tokens.dto.AssetsDto)2