Search in sources :

Example 26 with Initiative

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);
}
Also used : ModelDto(org.collectiveone.modules.model.dto.ModelDto) ModelViewDto(org.collectiveone.modules.model.dto.ModelViewDto) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) Initiative(org.collectiveone.modules.initiatives.Initiative) Transactional(javax.transaction.Transactional)

Example 27 with Initiative

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());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) Initiative(org.collectiveone.modules.initiatives.Initiative) Transactional(javax.transaction.Transactional)

Example 28 with Initiative

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());
}
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 29 with Initiative

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));
}
Also used : GetResult(org.collectiveone.common.dto.GetResult) UUID(java.util.UUID) Initiative(org.collectiveone.modules.initiatives.Initiative) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 30 with Initiative

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Initiative(org.collectiveone.modules.initiatives.Initiative)

Aggregations

Initiative (org.collectiveone.modules.initiatives.Initiative)32 Transactional (javax.transaction.Transactional)15 UUID (java.util.UUID)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 PostResult (org.collectiveone.common.dto.PostResult)11 GetResult (org.collectiveone.common.dto.GetResult)10 ArrayList (java.util.ArrayList)4 TransferDto (org.collectiveone.modules.tokens.dto.TransferDto)4 ActivityDto (org.collectiveone.modules.activity.dto.ActivityDto)3 PageRequest (org.springframework.data.domain.PageRequest)3 Email (com.sendgrid.Email)2 Personalization (com.sendgrid.Personalization)2 Timestamp (java.sql.Timestamp)2 Assignation (org.collectiveone.modules.assignations.Assignation)2 ModelCardWrapper (org.collectiveone.modules.model.ModelCardWrapper)2 ModelSection (org.collectiveone.modules.model.ModelSection)2 ModelView (org.collectiveone.modules.model.ModelView)2 TokenMint (org.collectiveone.modules.tokens.TokenMint)2 TokenType (org.collectiveone.modules.tokens.TokenType)2 AssetsDto (org.collectiveone.modules.tokens.dto.AssetsDto)2