Search in sources :

Example 31 with Transactional

use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method addMemberOrGet.

@Transactional
public Member addMemberOrGet(UUID initiativeId, UUID c1Id, DecisionMakerRole role) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    AppUser memberUser = appUserRepository.findByC1Id(c1Id);
    Member existingMember = memberRepository.findByInitiative_IdAndUser_C1Id(initiativeId, c1Id);
    if (existingMember != null) {
        return existingMember;
    }
    Member member = new Member();
    member.setInitiative(initiative);
    member.setUser(memberUser);
    member = memberRepository.save(member);
    initiative.getMembers().add(member);
    initiativeRepository.save(initiative);
    if (role.equals(DecisionMakerRole.ADMIN) || role.equals(DecisionMakerRole.EDITOR)) {
        governanceService.addDecisionMaker(initiative.getGovernance().getId(), memberUser.getC1Id(), role);
    }
    /* members are subscribed to initiatives by default */
    activityService.addSubscriber(initiativeId, memberUser.getC1Id(), SubscriptionElementType.INITIATIVE);
    return member;
}
Also used : AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 32 with Transactional

use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method getOfUser.

@Transactional
public GetResult<List<InitiativeDto>> getOfUser(UUID userC1Id) {
    /* return all super-initiatives (initiatives without parent initiatives) 
		 * and include all sub-initiativespf each of them */
    AppUser user = appUserRepository.findByC1Id(userC1Id);
    /* get all initiatives in which the user is a contributor */
    List<Initiative> superInitiatives = getSuperInitiativesOfMember(user.getC1Id());
    List<InitiativeDto> initiativesDtos = new ArrayList<InitiativeDto>();
    for (Initiative initiative : superInitiatives) {
        if (initiative.getStatus() == InitiativeStatus.ENABLED) {
            InitiativeDto dto = initiative.toDto();
            dto.setLoggedMembership(getMemberAndInParent(initiative.getId(), user.getC1Id()));
            /* look for the full sub-initiative tree of each super initiative */
            List<InitiativeDto> subInitiatives = getSubinitiativesTree(initiative.getId(), user.getC1Id());
            dto.setSubInitiatives(subInitiatives);
            initiativesDtos.add(dto);
        }
    }
    return new GetResult<List<InitiativeDto>>("success", "initiatives retrieved", initiativesDtos);
}
Also used : NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 33 with Transactional

use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method getOrAddMember.

@Transactional
public Member getOrAddMember(UUID initiativeId, UUID userId) {
    Member member = memberRepository.findByInitiative_IdAndUser_C1Id(initiativeId, userId);
    if (member == null) {
        Initiative initiative = initiativeRepository.findById(initiativeId);
        AppUser user = appUserRepository.findByC1Id(userId);
        member = new Member();
        member.setInitiative(initiative);
        member.setUser(user);
        member = memberRepository.save(member);
    }
    return member;
}
Also used : AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 34 with Transactional

use of javax.transaction.Transactional 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 35 with Transactional

use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method getInitiativeAssetsDtoLight.

/**
 */
@Transactional
public List<AssetsDto> getInitiativeAssetsDtoLight(UUID id) {
    Initiative initiative = initiativeRepository.findById(id);
    List<TokenType> ownTokens = initiative.getTokenTypes();
    List<TokenType> tokenTypes = tokenService.getTokenTypesHeldBy(initiative.getId());
    /* add own tokens even if the initiative does not have them */
    for (TokenType own : ownTokens) {
        if (!tokenTypes.contains(own)) {
            tokenTypes.add(own);
        }
    }
    List<AssetsDto> assets = new ArrayList<AssetsDto>();
    for (TokenType token : tokenTypes) {
        AssetsDto asset = new AssetsDto();
        asset.setAssetId(token.getId().toString());
        asset.setAssetName(token.getName());
        assets.add(asset);
    }
    return assets;
}
Also used : TokenType(org.collectiveone.modules.tokens.TokenType) ArrayList(java.util.ArrayList) AssetsDto(org.collectiveone.modules.tokens.dto.AssetsDto) Transactional(javax.transaction.Transactional)

Aggregations

Transactional (javax.transaction.Transactional)314 Test (org.junit.Test)100 PostResult (org.collectiveone.common.dto.PostResult)29 ArrayList (java.util.ArrayList)25 UserDO (org.neusoft.neubbs.entity.UserDO)21 Timestamp (java.sql.Timestamp)18 TopicDO (org.neusoft.neubbs.entity.TopicDO)18 Initiative (org.collectiveone.modules.initiatives.Initiative)16 GetResult (org.collectiveone.common.dto.GetResult)15 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)13 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)13 HashMap (java.util.HashMap)12 Date (java.util.Date)11 AppUser (org.collectiveone.modules.users.AppUser)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 UUID (java.util.UUID)10 RolesAllowed (javax.annotation.security.RolesAllowed)10 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)10 IOException (java.io.IOException)9 Booking (org.apache.karaf.examples.jpa.Booking)9