Search in sources :

Example 41 with PostResult

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

the class ModelService method createCardWrapper.

@Transactional
public PostResult createCardWrapper(ModelCardDto cardDto, UUID sectionId, UUID creatorId) {
    ModelSection section = modelSectionRepository.findById(sectionId);
    if (section == null)
        return new PostResult("error", "view not found", "");
    ModelCard card = cardDto.toEntity(null, cardDto, null);
    card = modelCardRepository.save(card);
    if (cardDto.getNewImageFileId() != null) {
        UUID imageFileId = cardDto.getNewImageFileId().equals("") ? null : UUID.fromString(cardDto.getNewImageFileId());
        if (imageFileId != null) {
            /* copy image from temporary location to card fixed location, needed the card ID for this */
            UUID newFileId = fileService.copyImageAfterCreationToCard(creatorId, imageFileId, card.getId());
            if (newFileId != null) {
                FileStored newImageFile = fileStoredRepository.findById(newFileId);
                card.setImageFile(newImageFile);
            }
        }
    }
    ModelCardWrapper cardWrapper = new ModelCardWrapper();
    cardWrapper.setCard(card);
    cardWrapper.setOtherProperties(cardDto);
    cardWrapper.setInitiative(section.getInitiative());
    cardWrapper = modelCardWrapperRepository.save(cardWrapper);
    /* add location */
    if (cardDto.getIxInSection() == null) {
        /* at the end */
        section.getCardsWrappers().add(cardWrapper);
    } else {
        if (cardDto.getIxInSection() == -1) {
            /* at the end */
            section.getCardsWrappers().add(cardWrapper);
        } else {
            /* at a given ix */
            section.getCardsWrappers().add(cardDto.getIxInSection(), cardWrapper);
        }
    }
    modelSectionRepository.save(section);
    activityService.modelCardWrapperCreated(cardWrapper, section, appUserRepository.findByC1Id(creatorId));
    return new PostResult("success", "card created", card.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) FileStored(org.collectiveone.modules.files.FileStored) Transactional(javax.transaction.Transactional)

Example 42 with PostResult

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

the class ModelService method editCardWrapper.

@Transactional
public PostResult editCardWrapper(UUID initiativeId, UUID cardWrapperId, ModelCardDto cardDto, UUID creatorId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    if (initiative == null)
        return new PostResult("error", "initiative not found", "");
    ModelCardWrapper cardWrapper = modelCardWrapperRepository.findById(cardWrapperId);
    if (cardWrapper == null)
        return new PostResult("error", "card wrapper not found", "");
    ModelCard originalCard = cardWrapper.getCard();
    cardWrapper.getOldVersions().add(originalCard);
    ModelCard card = cardDto.toEntity(null, cardDto, null);
    /* update or remove image */
    if (cardDto.getNewImageFileId() != null) {
        if (!cardDto.getNewImageFileId().equals("REMOVE")) {
            UUID imageFileId = cardDto.getNewImageFileId().equals("") ? null : UUID.fromString(cardDto.getNewImageFileId());
            FileStored imageFile = fileStoredRepository.findById(imageFileId);
            card.setImageFile(imageFile);
        } else {
            card.setImageFile(null);
        }
    } else {
        /* use the same image */
        card.setImageFile(originalCard.getImageFile());
    }
    card = modelCardRepository.save(card);
    cardWrapper.setCard(card);
    cardWrapper.setOtherProperties(cardDto);
    /* this inSections actually refer to add to new sections */
    for (ModelSectionDto sectionDto : cardDto.getInSections()) {
        ModelSection section = modelSectionRepository.findById(UUID.fromString(sectionDto.getId()));
        if (section != null) {
            section.getCardsWrappers().add(cardWrapper);
        }
    }
    activityService.modelCardWrapperEdited(cardWrapper, appUserRepository.findByC1Id(creatorId));
    return new PostResult("success", "card edited", cardWrapper.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) FileStored(org.collectiveone.modules.files.FileStored) Initiative(org.collectiveone.modules.initiatives.Initiative) ModelSectionDto(org.collectiveone.modules.model.dto.ModelSectionDto) Transactional(javax.transaction.Transactional)

Example 43 with PostResult

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

the class FileService method uploadCardImageBeforeCreation.

@Transactional
public PostResult uploadCardImageBeforeCreation(UUID userId, MultipartFile file) throws IOException {
    try (InputStream input = file.getInputStream()) {
        try {
            ImageIO.read(input).toString();
            String key = "CardImagesAtCreation/" + userId;
            FileStored fileUploaded = handleFileUpload(userId, key, file, null);
            if (fileUploaded != null) {
                return new PostResult("success", "image uploaded", fileUploaded.getId().toString());
            }
            return new PostResult("error", "error uploading image", "");
        } catch (Exception e) {
            // It's not an image.
            return new PostResult("error", "only image files are supported", "");
        }
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) InputStream(java.io.InputStream) IOException(java.io.IOException) Transactional(javax.transaction.Transactional)

Example 44 with PostResult

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

the class InitiativesController method deleteInitiative.

@RequestMapping(path = "/initiative/{initiativeId}", method = RequestMethod.DELETE)
public PostResult deleteInitiative(@PathVariable("initiativeId") String initiativeIdStr) {
    if (getLoggedUser() == null) {
        return new PostResult("error", "endpoint enabled users only", null);
    }
    UUID initiativeId = UUID.fromString(initiativeIdStr);
    DecisionVerdict canRevert = governanceService.canDeleteInitiative(initiativeId, getLoggedUser().getC1Id());
    if (canRevert == DecisionVerdict.DENIED) {
        return new PostResult("error", "revert of assignation not authorized", "");
    }
    return initiativeService.delete(initiativeId, getLoggedUser().getC1Id());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) DecisionVerdict(org.collectiveone.modules.governance.DecisionVerdict) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with PostResult

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

the class MessageService method postMessage.

@Transactional
public PostResult postMessage(MessageDto messageDto, UUID authorId, MessageThreadContextType contextType, UUID elementId) {
    AppUser author = appUserRepository.findByC1Id(authorId);
    Message message = messageDto.toEntity(messageDto, author);
    message = messageRepository.save(message);
    MessageThread thread = getOrCreateThreadFromElementId(contextType, elementId);
    thread.getMessages().add(message);
    message.setThread(thread);
    message = messageRepository.save(message);
    thread = messageThreadRepository.save(thread);
    activityService.messagePosted(message, author, contextType, elementId);
    return new PostResult("success", "message posted", message.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) AppUser(org.collectiveone.modules.users.AppUser) 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