Search in sources :

Example 21 with PostResult

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

the class InitiativeService method wantToContribute.

@Transactional
public PostResult wantToContribute(UUID initiativeId, UUID userId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    AppUser user = appUserRepository.findByC1Id(userId);
    List<DecisionMaker> admins = decisionMakerRepository.findByGovernance_IdAndRole(initiative.getGovernance().getId(), DecisionMakerRole.ADMIN);
    for (DecisionMaker admin : admins) {
        WantToContributeNotification notification = new WantToContributeNotification();
        notification.setInitiative(initiative);
        notification.setAdmin(admin.getUser());
        notification.setUser(user);
        notification.setEmailState(NotificationEmailState.PENDING);
        wantToContributeRepository.save(notification);
    }
    return new PostResult("success", "notifications recorded for sending", null);
}
Also used : WantToContributeNotification(org.collectiveone.modules.activity.WantToContributeNotification) PostResult(org.collectiveone.common.dto.PostResult) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker) AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 22 with PostResult

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

the class TokenController method mintTokens.

@RequestMapping(path = "/token/{tokenId}/mint", method = RequestMethod.PUT)
public PostResult mintTokens(@PathVariable("tokenId") String tokenIdStr, @RequestBody TokenMintDto mintDto) {
    if (getLoggedUser() == null) {
        return new PostResult("error", "endpoint enabled users only", null);
    }
    UUID tokenId = UUID.fromString(tokenIdStr);
    if (governanceService.canMintTokens(tokenId, getLoggedUser().getC1Id()) == DecisionVerdict.DENIED) {
        return new PostResult("error", "not authorized", "");
    }
    Initiative initiative = initiativeService.findByTokenType_Id(tokenId);
    String result = tokenTransferService.mintToInitiative(tokenId, initiative.getId(), getLoggedUser().getC1Id(), mintDto);
    if (result.equals("success")) {
        return new PostResult("success", "tokens minted", tokenId.toString());
    } else {
        return new PostResult("error", "error while minting tokens", "");
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) Initiative(org.collectiveone.modules.initiatives.Initiative) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with PostResult

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

the class FileService method uploadInitiativeImage.

@Transactional
public PostResult uploadInitiativeImage(UUID userId, UUID initiativeId, MultipartFile file) throws IOException {
    try (InputStream input = file.getInputStream()) {
        try {
            ImageIO.read(input).toString();
            String key = "InitiativeImages/" + initiativeId.toString();
            FileStored fileUploaded = handleFileUpload(userId, key, file, initiativeId);
            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 24 with PostResult

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

the class FileService method uploadCardImage.

@Transactional
public PostResult uploadCardImage(UUID userId, UUID cardWrapperId, MultipartFile file) throws IOException {
    try (InputStream input = file.getInputStream()) {
        try {
            ImageIO.read(input).toString();
            Initiative initiative = modelService.getCardWrapperInitiative(cardWrapperId);
            String key = "CardImages/" + cardWrapperId.toString();
            FileStored fileUploaded = handleFileUpload(userId, key, file, initiative.getId());
            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) Initiative(org.collectiveone.modules.initiatives.Initiative) IOException(java.io.IOException) Transactional(javax.transaction.Transactional)

Example 25 with PostResult

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

the class FilesController method uploadCardImage.

@RequestMapping(value = "/upload/cardImage/{cardWrapperId}", method = RequestMethod.POST)
@ResponseBody
public PostResult uploadCardImage(@PathVariable("cardWrapperId") String cardWrapperIdStr, @RequestParam("file") MultipartFile file) throws IOException {
    if (getLoggedUser() == null) {
        return new PostResult("error", "endpoint enabled users only", "");
    }
    UUID cardWrapperId = UUID.fromString(cardWrapperIdStr);
    Initiative initiative = modelService.getCardWrapperInitiative(cardWrapperId);
    if (governanceService.canEditModel(initiative.getId(), getLoggedUserId()) == DecisionVerdict.DENIED) {
        return new PostResult("error", "not authorized", "");
    }
    return fileService.uploadCardImage(getLoggedUserId(), cardWrapperId, file);
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) Initiative(org.collectiveone.modules.initiatives.Initiative) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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