Search in sources :

Example 1 with ModelSectionDto

use of org.collectiveone.modules.model.dto.ModelSectionDto in project CollectiveOneWebapp by CollectiveOne.

the class ModelSection method toDto.

public ModelSectionDto toDto() {
    ModelSectionDto sectionDto = new ModelSectionDto();
    sectionDto.setId(id.toString());
    sectionDto.setTitle(title);
    sectionDto.setDescription(description);
    sectionDto.setnSubsections(subsections.size());
    sectionDto.setnCards(cardsWrappers.size());
    if (initiative != null)
        sectionDto.setInitiativeId(initiative.getId().toString());
    return sectionDto;
}
Also used : ModelSectionDto(org.collectiveone.modules.model.dto.ModelSectionDto)

Example 2 with ModelSectionDto

use of org.collectiveone.modules.model.dto.ModelSectionDto in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method getSectionDto.

@Transactional
public ModelSectionDto getSectionDto(UUID sectionId, Integer level, UUID requestByUserId) {
    ModelSection section = modelSectionRepository.findById(sectionId);
    ModelSectionDto sectionDto = section.toDto();
    /* set parent sections or views */
    List<ModelSection> inSections = modelSectionRepository.findParentSections(section.getId());
    List<ModelView> inViews = modelSectionRepository.findParentViews(section.getId());
    for (ModelSection inSection : inSections) {
        sectionDto.getInSections().add(inSection.toDto());
    }
    for (ModelView inView : inViews) {
        sectionDto.getInViews().add(inView.toDto());
    }
    sectionDto = addSectionSubElements(sectionDto, section.getId(), level, requestByUserId);
    return sectionDto;
}
Also used : ModelSectionDto(org.collectiveone.modules.model.dto.ModelSectionDto) Transactional(javax.transaction.Transactional)

Example 3 with ModelSectionDto

use of org.collectiveone.modules.model.dto.ModelSectionDto in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method initializeModel.

@Transactional
private PostResult initializeModel(UUID initiativeId, UUID creatorId) {
    ModelViewDto viewDto = new ModelViewDto();
    viewDto.setTitle("General View");
    viewDto.setDescription("Initial auto-generated sample view. You can edit or delete it at will.");
    PostResult result = modelService.createView(initiativeId, viewDto, creatorId, false);
    ModelSectionDto sectionDto = new ModelSectionDto();
    sectionDto.setTitle("Section");
    sectionDto.setDescription("Initial auto-generated sample section. You can edit or delete it at will.");
    PostResult result2 = modelService.createSection(sectionDto, null, UUID.fromString(result.getElementId()), creatorId, false);
    return result2;
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) ModelViewDto(org.collectiveone.modules.model.dto.ModelViewDto) ModelSectionDto(org.collectiveone.modules.model.dto.ModelSectionDto) Transactional(javax.transaction.Transactional)

Example 4 with ModelSectionDto

use of org.collectiveone.modules.model.dto.ModelSectionDto 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)

Aggregations

ModelSectionDto (org.collectiveone.modules.model.dto.ModelSectionDto)4 Transactional (javax.transaction.Transactional)3 PostResult (org.collectiveone.common.dto.PostResult)2 UUID (java.util.UUID)1 FileStored (org.collectiveone.modules.files.FileStored)1 Initiative (org.collectiveone.modules.initiatives.Initiative)1 ModelViewDto (org.collectiveone.modules.model.dto.ModelViewDto)1