Search in sources :

Example 1 with TokenMint

use of org.collectiveone.modules.tokens.TokenMint 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 2 with TokenMint

use of org.collectiveone.modules.tokens.TokenMint 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 3 with TokenMint

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

TokenMint (org.collectiveone.modules.tokens.TokenMint)3 TokenType (org.collectiveone.modules.tokens.TokenType)3 Transactional (javax.transaction.Transactional)2 PostResult (org.collectiveone.common.dto.PostResult)2 InitiativeTransfer (org.collectiveone.modules.tokens.InitiativeTransfer)2 Timestamp (java.sql.Timestamp)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)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 Initiative (org.collectiveone.modules.initiatives.Initiative)1 ModelCardWrapper (org.collectiveone.modules.model.ModelCardWrapper)1 ModelSection (org.collectiveone.modules.model.ModelSection)1 ModelView (org.collectiveone.modules.model.ModelView)1 TransferDto (org.collectiveone.modules.tokens.dto.TransferDto)1 AppUser (org.collectiveone.modules.users.AppUser)1