use of org.collectiveone.modules.files.FileStored in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method edit.
@Transactional
public PostResult edit(UUID initiativeId, UUID userId, NewInitiativeDto initiativeDto) {
Initiative initiative = initiativeRepository.findById(initiativeId);
InitiativeMeta initiativeMeta = initiative.getMeta();
String oldName = initiativeMeta.getName();
String oldDriver = initiativeMeta.getDriver();
initiativeMeta.setName(initiativeDto.getName());
initiativeMeta.setDriver(initiativeDto.getDriver());
initiativeMeta.setColor(initiativeDto.getColor());
initiativeMeta.setModelEnabled(initiativeDto.getModelEnabled());
if (initiativeDto.getVisibility() != null) {
initiativeMeta.setVisibility(InitiativeVisibility.valueOf(initiativeDto.getVisibility()));
}
/* remove and add all tags */
initiativeMeta.getTags().removeAll(initiativeMeta.getTags());
for (InitiativeTagDto tagDto : initiativeDto.getTags()) {
InitiativeTag tag = initiativeTagRepository.findById(UUID.fromString(tagDto.getId()));
initiativeMeta.getTags().add(tag);
}
/* update or remove image */
if (initiativeDto.getNewImageFileId() != null) {
if (!initiativeDto.getNewImageFileId().equals("REMOVE")) {
UUID imageFileId = initiativeDto.getNewImageFileId().equals("") ? null : UUID.fromString(initiativeDto.getNewImageFileId());
FileStored imageFile = fileStoredRepository.findById(imageFileId);
initiativeMeta.setImageFile(imageFile);
} else {
initiativeMeta.setImageFile(null);
}
}
initiativeMetaRepository.save(initiativeMeta);
if (!oldName.equals(initiativeDto.getName()) || !oldDriver.equals(initiativeDto.getDriver())) {
/* notify only if actually different */
activityService.initiativeEdited(initiative, appUserRepository.findByC1Id(userId), oldName, oldDriver);
}
return new PostResult("success", "initaitive updated", initiative.getId().toString());
}
use of org.collectiveone.modules.files.FileStored 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.modules.files.FileStored 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());
}
Aggregations