Search in sources :

Example 1 with TokenType

use of org.collectiveone.modules.tokens.TokenType in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method getInitiativeAssetsDtoLight.

/**
 */
@Transactional
public List<AssetsDto> getInitiativeAssetsDtoLight(UUID id) {
    Initiative initiative = initiativeRepository.findById(id);
    List<TokenType> ownTokens = initiative.getTokenTypes();
    List<TokenType> tokenTypes = tokenService.getTokenTypesHeldBy(initiative.getId());
    /* add own tokens even if the initiative does not have them */
    for (TokenType own : ownTokens) {
        if (!tokenTypes.contains(own)) {
            tokenTypes.add(own);
        }
    }
    List<AssetsDto> assets = new ArrayList<AssetsDto>();
    for (TokenType token : tokenTypes) {
        AssetsDto asset = new AssetsDto();
        asset.setAssetId(token.getId().toString());
        asset.setAssetName(token.getName());
        assets.add(asset);
    }
    return assets;
}
Also used : TokenType(org.collectiveone.modules.tokens.TokenType) ArrayList(java.util.ArrayList) AssetsDto(org.collectiveone.modules.tokens.dto.AssetsDto) Transactional(javax.transaction.Transactional)

Example 2 with TokenType

use of org.collectiveone.modules.tokens.TokenType in project CollectiveOneWebapp by CollectiveOne.

the class Initiative method toDto.

public InitiativeDto toDto() {
    InitiativeDto dto = new InitiativeDto();
    dto.setId(id.toString());
    dto.setCreator(creator.toDtoLight());
    dto.setStatus(status.toString());
    dto.setMeta(meta.toDto());
    if (tokenTypes != null) {
        for (TokenType tokenType : tokenTypes) {
            dto.getOwnAssetsIds().add(tokenType.getId().toString());
        }
    }
    return dto;
}
Also used : TokenType(org.collectiveone.modules.tokens.TokenType) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto)

Example 3 with TokenType

use of org.collectiveone.modules.tokens.TokenType in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method getMembersAndSubmembers.

public InitiativeMembersDto getMembersAndSubmembers(UUID initiativeId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    InitiativeMembersDto initiativeMembers = new InitiativeMembersDto();
    initiativeMembers.setInitiativeId(initiative.getId().toString());
    initiativeMembers.setInitiativeName(initiative.getMeta().getName());
    List<TokenType> tokenTypes = tokenService.getTokenTypesHeldBy(initiative.getId());
    /* add members of this initiative */
    for (Member member : initiative.getMembers()) {
        MemberDto memberDto = new MemberDto();
        memberDto.setId(member.getId().toString());
        memberDto.setUser(member.getUser().toDtoLight());
        /* governance related data */
        DecisionMaker decisionMaker = governanceService.getDecisionMaker(initiative.getGovernance().getId(), member.getUser().getC1Id());
        if (decisionMaker != null) {
            memberDto.setRole(decisionMaker.getRole().toString());
        } else {
            memberDto.setRole(DecisionMakerRole.MEMBER.toString());
        }
        /* assets related data */
        for (TokenType token : tokenTypes) {
            memberDto.getReceivedAssets().add(tokenService.getTokensOfHolderDtoLight(token.getId(), member.getUser().getC1Id()));
        }
        initiativeMembers.getMembers().add(memberDto);
    }
    /* add the members of all sub-initiatives too */
    for (InitiativeDto subInitiative : getSubinitiativesTree(initiative.getId(), null)) {
        /* recursively call with subinitiatives */
        initiativeMembers.getSubinitiativesMembers().add(getMembersAndSubmembers(UUID.fromString(subInitiative.getId())));
    }
    return initiativeMembers;
}
Also used : TokenType(org.collectiveone.modules.tokens.TokenType) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) MemberDto(org.collectiveone.modules.initiatives.dto.MemberDto) InitiativeMembersDto(org.collectiveone.modules.initiatives.dto.InitiativeMembersDto) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker)

Example 4 with TokenType

use of org.collectiveone.modules.tokens.TokenType in project CollectiveOneWebapp by CollectiveOne.

the class EmailService method getActivityMessage.

private String getActivityMessage(Notification notification) {
    Activity act = notification.getActivity();
    Initiative initiative = act.getInitiative();
    Initiative subInitiative = act.getSubInitiative();
    String transferredAssets = (act.getInitiativeTransfers() != null) ? getTransferString(act.getInitiativeTransfers()) : "";
    TokenType tokenType = notification.getActivity().getTokenType();
    TokenMint mint = notification.getActivity().getMint();
    Assignation assignation = notification.getActivity().getAssignation();
    InitiativeTransfer transfer = notification.getActivity().getInitiativeTransfer();
    ModelView modelView = notification.getActivity().getModelView();
    ModelSection modelSection = notification.getActivity().getModelSection();
    ModelCardWrapper modelCardWrapper = notification.getActivity().getModelCardWrapper();
    ModelSection onSection = notification.getActivity().getOnSection();
    ModelView onView = notification.getActivity().getOnView();
    ModelSection fromSection = notification.getActivity().getFromSection();
    ModelView fromView = notification.getActivity().getFromView();
    String message = "";
    switch(notification.getActivity().getType()) {
        case INITIATIVE_CREATED:
            return "<p>created the " + getInitiativeAnchor(initiative) + " initiative and added you as a member.</p>";
        case SUBINITIATIVE_CREATED:
            return "<p>created the " + getInitiativeAnchor(subInitiative) + " sub-initiative and transferred " + transferredAssets + " to it.</p>";
        case INITIATIVE_EDITED:
            return "<p>edited the name or purpose of the " + getInitiativeAnchor(initiative) + " initiative.</p>";
        case INITIATIVE_DELETED:
            return "<p>deleted the initiative " + getInitiativeAnchor(initiative) + ". All its assets, if any, have been transferred to its parent initiative," + "if the parent exist.</p> ";
        case TOKENS_MINTED:
            return "<p>minted " + mint.getValue() + " " + mint.getToken().getName() + " with motive: " + mint.getMotive() + ".</p>";
        case TOKEN_CREATED:
            return "<p>created a new token type called " + tokenType.getName() + " in " + getInitiativeAnchor(initiative) + ", and minted " + mint.getValue() + " units.</p>";
        case PR_ASSIGNATION_CREATED:
            Evaluator evaluator = null;
            /* check if this member is an evaluator */
            for (Evaluator thisEvaluator : assignation.getEvaluators()) {
                if (thisEvaluator.getUser().getC1Id() == notification.getSubscriber().getUser().getC1Id()) {
                    evaluator = thisEvaluator;
                }
            }
            String receiversList = "";
            for (int ix = 0; ix < assignation.getReceivers().size(); ix++) {
                /* first element starts the string */
                if (ix == 0) {
                    receiversList += "";
                }
                /* next elements add a comma or 'and' and a space */
                if (ix > 0) {
                    if (ix == assignation.getReceivers().size() - 1) {
                        receiversList += " and ";
                    } else {
                        receiversList += ", ";
                    }
                }
                if (assignation.getReceivers().get(ix).getUser().getC1Id() == notification.getSubscriber().getUser().getC1Id()) {
                    receiversList += "you";
                } else {
                    receiversList += assignation.getReceivers().get(ix).getUser().getProfile().getNickname();
                }
            }
            message = "<p>created a new peer-reviewed " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " to be distributed among " + receiversList + ", with motive: </p><p>" + assignation.getMotive() + ".</p>";
            if (evaluator != null) {
                Date closeDate = assignation.getConfig().getMaxClosureDate();
                SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, ''yy");
                message += "<p>You are one of the evaluators of this transfer! Please visit the " + getAssignationAnchor(assignation) + " page to make your evaluation.</p>" + "<p>You have until " + dateFormat.format(closeDate) + " at this time of the day to do it.</p>";
            }
            return message;
        case PR_ASSIGNATION_DONE:
            return "<p>Peer-reviewed " + getAssignationAnchor(assignation) + " with motive: </p>" + "<p>" + assignation.getMotive() + "</p>" + "<p>has been closed.</p>" + "<p>" + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " have been transferred to its receivers.</p>";
        case D_ASSIGNATION_CREATED:
            return "<p>made a direct " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " to " + assignation.getReceivers().get(0).getUser().getProfile().getNickname() + ", with motive: </p><p>" + assignation.getMotive() + ".</p>";
        case INITIATIVE_TRANSFER:
            return "<p>made a transfer of " + transfer.getValue() + " " + transfer.getTokenType().getName() + " to " + getInitiativeAnchor(transfer.getTo()) + ", with motive: </p><p>" + transfer.getMotive() + ".</p>";
        case ASSIGNATION_REVERT_ORDERED:
            message = "<p>wants to revert the " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " with motive: " + assignation.getMotive() + ".</p> ";
            for (Receiver receiver : assignation.getReceivers()) {
                if (receiver.getUser().getC1Id().equals(notification.getSubscriber().getUser().getC1Id())) {
                    message += "<p>You were one of the transfer receivers, so you will have to approve this revert by " + "visiting the " + getAssignationAnchor(assignation) + " page.</p>";
                }
            }
            return message;
        case ASSIGNATION_REVERT_CANCELLED:
            return "<p>ordered a revert of the " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " with motive: " + assignation.getMotive() + ", but this revert has been cancelled.</p> ";
        case ASSIGNATION_REVERTED:
            return "<p>ordered a revert of the " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " with motive: " + assignation.getMotive() + ", and the revert has been accepted.</p> ";
        case ASSIGNATION_DELETED:
            return "<p>deleted the ongoing " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " with motive: " + assignation.getMotive() + ". No tokens have or will be transferred.</p> ";
        case MODEL_VIEW_CREATED:
            return "<p>created a new model view named " + getModelViewAnchor(modelView) + "</p> ";
        case MODEL_VIEW_EDITED:
            return "<p>edited the model " + getModelViewAnchor(modelView) + " view</p> ";
        case MODEL_VIEW_DELETED:
            return "<p>deleted the model " + getModelViewAnchor(modelView) + " view</p> ";
        case MODEL_SECTION_CREATED:
            if (onSection != null) {
                message = "<p>created a new section " + getModelSectionAnchor(modelSection) + " under section " + getModelSectionAnchor(onSection) + "</p> ";
            } else {
                message = "<p>created a new section " + getModelSectionAnchor(modelSection) + " under the " + getModelViewAnchor(onView) + " view</p> ";
            }
            return message;
        case MODEL_SECTION_EDITED:
            return "<p>edited the model section " + getModelSectionAnchor(modelSection) + "</p> ";
        case MODEL_SECTION_DELETED:
            return "<p>deleted the model section " + getModelSectionAnchor(modelSection) + "</p> ";
        case MODEL_CARDWRAPPER_CREATED:
            return "<p>created a new card " + getModelCardWrapperAnchor(modelCardWrapper, onSection) + " in the " + getModelSectionAnchor(onSection) + " section</p> ";
        case MODEL_CARDWRAPPER_EDITED:
            return "<p>edited the model card " + getModelCardWrapperAnchor(modelCardWrapper) + "</p> ";
        case MODEL_CARDWRAPPER_DELETED:
            return "<p>deleted the model card " + getModelCardWrapperAnchor(modelCardWrapper) + "</p> ";
        case MODEL_SECTION_ADDED:
            if (onSection != null) {
                message = "<p>added the section " + getModelSectionAnchor(modelSection) + " as sub-section of " + getModelSectionAnchor(onSection) + "</p> ";
            } else {
                message = "<p>added the section " + getModelSectionAnchor(modelSection) + " under the " + getModelViewAnchor(onView) + " view</p> ";
            }
            return message;
        case MODEL_SECTION_MOVED:
            if (onSection != null) {
                if (fromSection != null) {
                    message = "<p>moved the section " + getModelSectionAnchor(modelSection) + " from section " + getModelSectionAnchor(fromSection) + " to section " + getModelSectionAnchor(onSection) + "</p> ";
                } else {
                    message = "<p>moved the section " + getModelSectionAnchor(modelSection) + " from view " + getModelViewAnchor(fromView) + " to section " + getModelSectionAnchor(onSection) + "</p> ";
                }
            } else {
                if (fromSection != null) {
                    message = "<p>moved the section " + getModelSectionAnchor(modelSection) + " from section " + getModelSectionAnchor(fromSection) + " to the " + getModelViewAnchor(onView) + "view</p> ";
                } else {
                    message = "<p>moved the section " + getModelSectionAnchor(modelSection) + " from view " + getModelViewAnchor(fromView) + " to the " + getModelViewAnchor(onView) + " view</p> ";
                }
            }
            return message;
        case MODEL_SECTION_REMOVED:
            if (fromSection != null) {
                message = "<p>removed the section " + getModelSectionAnchor(modelSection) + " from section " + getModelSectionAnchor(fromSection) + "</p> ";
            } else {
                message = "<p>removed the section " + getModelSectionAnchor(modelSection) + " from the " + getModelSectionAnchor(fromSection) + " view</p> ";
            }
            return message;
        case MODEL_CARDWRAPPER_ADDED:
            return "<p>added the card " + getModelCardWrapperAnchor(modelCardWrapper, onSection) + " under section " + getModelSectionAnchor(onSection) + "</p> ";
        case MODEL_CARDWRAPPER_MOVED:
            return "<p>moved the card " + getModelCardWrapperAnchor(modelCardWrapper, onSection) + " from section " + getModelSectionAnchor(fromSection) + " to section " + getModelSectionAnchor(onSection) + "</p> ";
        case MODEL_CARDWRAPPER_REMOVED:
            return "<p>removed the card " + getModelCardWrapperAnchor(modelCardWrapper, fromSection) + " from section " + getModelSectionAnchor(fromSection) + "</p> ";
        default:
            break;
    }
    return "";
}
Also used : ModelCardWrapper(org.collectiveone.modules.model.ModelCardWrapper) TokenMint(org.collectiveone.modules.tokens.TokenMint) Receiver(org.collectiveone.modules.assignations.Receiver) Assignation(org.collectiveone.modules.assignations.Assignation) Evaluator(org.collectiveone.modules.assignations.Evaluator) Initiative(org.collectiveone.modules.initiatives.Initiative) TokenMint(org.collectiveone.modules.tokens.TokenMint) Date(java.util.Date) TokenType(org.collectiveone.modules.tokens.TokenType) ModelSection(org.collectiveone.modules.model.ModelSection) ModelView(org.collectiveone.modules.model.ModelView) InitiativeTransfer(org.collectiveone.modules.tokens.InitiativeTransfer) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with TokenType

use of org.collectiveone.modules.tokens.TokenType 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)

Aggregations

TokenType (org.collectiveone.modules.tokens.TokenType)7 Transactional (javax.transaction.Transactional)3 PostResult (org.collectiveone.common.dto.PostResult)3 TokenMint (org.collectiveone.modules.tokens.TokenMint)3 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 Initiative (org.collectiveone.modules.initiatives.Initiative)2 InitiativeDto (org.collectiveone.modules.initiatives.dto.InitiativeDto)2 InitiativeTransfer (org.collectiveone.modules.tokens.InitiativeTransfer)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Assignation (org.collectiveone.modules.assignations.Assignation)1 Evaluator (org.collectiveone.modules.assignations.Evaluator)1 Receiver (org.collectiveone.modules.assignations.Receiver)1 BillDto (org.collectiveone.modules.assignations.dto.BillDto)1 EvaluatorDto (org.collectiveone.modules.assignations.dto.EvaluatorDto)1 ReceiverDto (org.collectiveone.modules.assignations.dto.ReceiverDto)1 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)1 DecisionMaker (org.collectiveone.modules.governance.DecisionMaker)1 InitiativeMembersDto (org.collectiveone.modules.initiatives.dto.InitiativeMembersDto)1