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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations