use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method getModel.
@Transactional
public GetResult<ModelDto> getModel(UUID initiativeId, Integer level, UUID requestById) {
Initiative initiative = initiativeRepository.findById(initiativeId);
if (initiative == null)
return new GetResult<ModelDto>("error", "initiative not found", null);
List<ModelViewDto> viewsDto = new ArrayList<ModelViewDto>();
List<ModelView> views = initiative.getModelViews();
for (ModelView view : views) {
ModelViewDto viewDto = view.toDto();
viewDto = addViewSubElements(viewDto, view.getId(), level, requestById);
viewsDto.add(viewDto);
}
ModelDto modelDto = new ModelDto();
modelDto.setViews(viewsDto);
return new GetResult<ModelDto>("success", "model found", modelDto);
}
use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method deleteView.
@Transactional
public PostResult deleteView(UUID viewId, UUID creatorId) {
ModelView view = modelViewRepository.findById(viewId);
Initiative initiative = view.getInitiative();
initiative.getModelViews().remove(view);
initiative.getModelViewsTrash().add(view);
initiativeRepository.save(initiative);
view = modelViewRepository.save(view);
activityService.modelViewDeleted(view, appUserRepository.findByC1Id(creatorId));
return new PostResult("success", "view deleted", view.getId().toString());
}
use of org.collectiveone.modules.initiatives.Initiative 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.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class FilesController method getFileData.
@RequestMapping(value = "/files/{fileId}", method = RequestMethod.GET)
@ResponseBody
public GetResult<FileStoredDto> getFileData(@PathVariable("fileId") String fileIdStr) {
UUID fileId = UUID.fromString(fileIdStr);
Initiative initiative = fileService.getFileInitiative(fileId);
if (initiative != null) {
if (!initiativeService.canAccess(initiative.getId(), getLoggedUserId())) {
return new GetResult<FileStoredDto>("error", "access denied", null);
}
}
return new GetResult<FileStoredDto>("success", "file retrieved", fileService.getFileData(fileId));
}
use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeRepositoryIfImpl method customSearch.
public List<Initiative> customSearch(SearchFiltersDto filters) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Initiative> criteria = builder.createQuery(Initiative.class);
Root<Initiative> initiativeRoot = criteria.from(Initiative.class);
criteria.select(initiativeRoot);
TypedQuery<Initiative> query = entityManager.createQuery(criteria);
List<Initiative> initiatives = query.getResultList();
for (Initiative init : initiatives) {
System.out.println(init.getId().toString());
}
return initiatives;
}
Aggregations