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());
}
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());
}
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());
}
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;
}
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, "");
}
}
Aggregations