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