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());
}
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());
}
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", "");
}
}
}
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());
}
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());
}
Aggregations