Search in sources :

Example 6 with PostResult

use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.

the class ModelController method addExistingCard.

@RequestMapping(path = "/initiative/{initiativeId}/model/section/{sectionId}/cardWrapper/{cardWrapperId}", method = RequestMethod.PUT)
public PostResult addExistingCard(@PathVariable("initiativeId") String initiativeIdStr, @PathVariable("sectionId") String sectionIdStr, @PathVariable("cardWrapperId") String cardWrapperIdStr, @RequestParam(name = "beforeCardWrapperId", defaultValue = "") String beforeCardWrapperIdStr) {
    if (getLoggedUser() == null) {
        return new PostResult("error", "endpoint enabled users only", null);
    }
    UUID initiativeId = UUID.fromString(initiativeIdStr);
    if (governanceService.canEditModel(initiativeId, getLoggedUser().getC1Id()) == DecisionVerdict.DENIED) {
        return new PostResult("error", "not authorized", "");
    }
    UUID beforeCardWrapperId = beforeCardWrapperIdStr.equals("") ? null : UUID.fromString(beforeCardWrapperIdStr);
    return modelService.addCardToSection(UUID.fromString(sectionIdStr), UUID.fromString(cardWrapperIdStr), beforeCardWrapperId, getLoggedUserId());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with PostResult

use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method createSection.

@Transactional
public PostResult createSection(ModelSectionDto sectionDto, UUID parentSectionId, UUID parentViewId, UUID creatorId, boolean register) {
    ModelSection section = sectionDto.toEntity(null, sectionDto);
    section = modelSectionRepository.save(section);
    if (parentSectionId != null) {
        ModelSection parent = modelSectionRepository.findById(parentSectionId);
        if (parent == null)
            return new PostResult("error", "parent section not found", "");
        parent.getSubsections().add(section);
        section.setInitiative(parent.getInitiative());
        if (register)
            activityService.modelSectionCreatedOnSection(section, parent, appUserRepository.findByC1Id(creatorId));
        modelSectionRepository.save(parent);
    } else {
        ModelView view = modelViewRepository.findById(parentViewId);
        if (view == null)
            return new PostResult("error", "view not found", "");
        view.getSections().add(section);
        section.setInitiative(view.getInitiative());
        if (register)
            activityService.modelSectionCreatedOnView(section, view, appUserRepository.findByC1Id(creatorId));
        modelViewRepository.save(view);
    }
    return new PostResult("success", "section created", section.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) Transactional(javax.transaction.Transactional)

Example 8 with PostResult

use of org.collectiveone.common.dto.PostResult 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 9 with PostResult

use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method setLikeToCard.

@Transactional
public PostResult setLikeToCard(UUID cardWrapperId, UUID authorId, boolean likeStatus) {
    ModelCardWrapper card = modelCardWrapperRepository.findById(cardWrapperId);
    AppUser author = appUserRepository.findByC1Id(authorId);
    CardLike like = cardLikeRepository.findByCardWrapperIdAndAuthor_c1Id(cardWrapperId, authorId);
    /* add the like*/
    if (likeStatus == true) {
        if (like == null) {
            like = new CardLike();
            like.setAuthor(author);
            like.setCardWrapper(card);
            cardLikeRepository.save(like);
        } else {
        /* nothing to do, the like is already registered */
        }
    } else {
        if (like != null) {
            cardLikeRepository.delete(like);
        } else {
        /* nothing to do, the like is already absent */
        }
    }
    return new PostResult("success", "like status changed", null);
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) AppUser(org.collectiveone.modules.users.AppUser) CardLike(org.collectiveone.modules.governance.CardLike) Transactional(javax.transaction.Transactional)

Example 10 with PostResult

use of org.collectiveone.common.dto.PostResult 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)

Aggregations

PostResult (org.collectiveone.common.dto.PostResult)47 Transactional (javax.transaction.Transactional)28 UUID (java.util.UUID)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 Initiative (org.collectiveone.modules.initiatives.Initiative)11 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)7 DecisionVerdict (org.collectiveone.modules.governance.DecisionVerdict)5 AppUser (org.collectiveone.modules.users.AppUser)5 Timestamp (java.sql.Timestamp)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 FileStored (org.collectiveone.modules.files.FileStored)3 TokenType (org.collectiveone.modules.tokens.TokenType)3 DecisionMaker (org.collectiveone.modules.governance.DecisionMaker)2 ModelSectionDto (org.collectiveone.modules.model.dto.ModelSectionDto)2 TokenMint (org.collectiveone.modules.tokens.TokenMint)2 ArrayList (java.util.ArrayList)1 WantToContributeNotification (org.collectiveone.modules.activity.WantToContributeNotification)1 BillDto (org.collectiveone.modules.assignations.dto.BillDto)1 EvaluationGradeDto (org.collectiveone.modules.assignations.dto.EvaluationGradeDto)1