use of org.collectiveone.modules.users.AppUser in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method setLikeToCard.
@Transactional
public PostResult setLikeToCard(UUID cardWrapperId, UUID authorId, boolean likeStatus) {
ModelCardWrapper card = modelCardWrapperRepository.findById(cardWrapperId);
AppUser author = appUserRepository.findByC1Id(authorId);
CardLike like = cardLikeRepository.findByCardWrapperIdAndAuthor_c1Id(cardWrapperId, authorId);
/* add the like*/
if (likeStatus == true) {
if (like == null) {
like = new CardLike();
like.setAuthor(author);
like.setCardWrapper(card);
cardLikeRepository.save(like);
} else {
/* nothing to do, the like is already registered */
}
} else {
if (like != null) {
cardLikeRepository.delete(like);
} else {
/* nothing to do, the like is already absent */
}
}
return new PostResult("success", "like status changed", null);
}
use of org.collectiveone.modules.users.AppUser 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 org.collectiveone.modules.users.AppUser 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 org.collectiveone.modules.users.AppUser 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 org.collectiveone.modules.users.AppUser in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method create.
@Transactional
private GetResult<Initiative> create(UUID c1Id, NewInitiativeDto initiativeDto) {
AppUser creator = appUserRepository.findByC1Id(c1Id);
if (creator == null) {
return new GetResult<Initiative>("error", "creator not found", null);
}
Initiative initiative = new Initiative();
/* Basic properties*/
initiative.setCreator(creator);
initiative.setStatus(InitiativeStatus.ENABLED);
InitiativeMeta meta = new InitiativeMeta();
meta.setName(initiativeDto.getName());
meta.setDriver(initiativeDto.getDriver());
meta.setCreationDate(new Timestamp(System.currentTimeMillis()));
meta.setModelEnabled(true);
if (!initiativeDto.getAsSubinitiative()) {
meta.setColor("#009ee3");
} else {
Initiative parent = initiativeRepository.findById(UUID.fromString(initiativeDto.getParentInitiativeId()));
meta.setColor(parent.getMeta().getColor());
}
meta = initiativeMetaRepository.save(meta);
initiative.setMeta(meta);
initiative = initiativeRepository.save(initiative);
/* Create the governace object of this initiative */
Governance governance = governanceService.create(initiative);
initiative.setGovernance(governance);
initiative = initiativeRepository.save(initiative);
activityService.newInitiativeCreated(initiative, initiative.getCreator());
return new GetResult<Initiative>("success", "initiative created", initiative);
}
Aggregations