use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.
the class Messages method send.
/**
* Sends message contained in the MessageInfo to the specified recipients. It some of the
* recipients do not exist, the routine does its best to deliver as many as possible
*
* @param info details of message including recipient(s)
* @return false if the message fails to be sent to all the intended recipients
*/
public boolean send(MessageInfo info) {
if (info == null || info.getAccounts().isEmpty() && info.getUserGroups().isEmpty())
return false;
boolean success = true;
Message message = new Message();
message.setDateSent(new Date());
message.setFromEmail(this.userId);
message.setMessage(info.getMessage());
message.setTitle(info.getTitle());
if (info.getAccounts() != null) {
for (AccountTransfer accountTransfer : info.getAccounts()) {
Account account = accountDAO.getByEmail(accountTransfer.getEmail());
if (account == null) {
success = false;
continue;
}
message.getDestinationAccounts().add(account);
}
}
if (info.getUserGroups() != null) {
for (UserGroup userGroup : info.getUserGroups()) {
Group group = DAOFactory.getGroupDAO().get(userGroup.getId());
if (group == null) {
Logger.warn("Could not retrieve group with id " + userGroup.getId() + " to send message");
success = false;
continue;
}
message.getDestinationGroups().add(group);
}
}
if (!success)
return false;
if (message.getDestinationAccounts().isEmpty() && message.getDestinationGroups().isEmpty())
return false;
return dao.create(message) != null;
}
use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.
the class GroupController method createGroup.
// create group without parent
public UserGroup createGroup(String userId, UserGroup info) {
if (info.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
String errMsg = "Non admin " + userId + " attempting to create public group";
Logger.error(errMsg);
return null;
}
if (info.getType() == null)
info.setType(GroupType.PRIVATE);
Account account = accountController.getByEmail(userId);
Group group = new Group();
group.setLabel(info.getLabel());
group.setDescription(info.getDescription() == null ? "" : info.getDescription());
group.setType(info.getType());
group.setOwner(account);
group = save(group);
for (AccountTransfer accountTransfer : info.getMembers()) {
Account memberAccount = accountController.getByEmail(accountTransfer.getEmail());
if (memberAccount == null)
continue;
memberAccount.getGroups().add(group);
accountController.save(memberAccount);
}
info = group.toDataTransferObject();
for (Account addedAccount : group.getMembers()) {
info.getMembers().add(addedAccount.toDataTransferObject());
}
info.setMemberCount(info.getMembers().size());
return info;
}
use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.
the class Groups method getMatchingGroups.
public List<UserGroup> getMatchingGroups(String token, int limit) {
Account account = accountDAO.getByEmail(this.userId);
List<Group> groups = dao.getMatchingGroups(account, token, limit);
List<UserGroup> results = new ArrayList<>(groups.size());
for (Group group : groups) {
results.add(group.toDataTransferObject());
}
return results;
}
use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.
the class Groups method addGroup.
/**
* Adds group to the list of groups for current user
*
* @param userGroup information about group to be added, including members (local and remote)
* @return added group
*/
public UserGroup addGroup(UserGroup userGroup) {
if (userGroup.getType() == null)
userGroup.setType(GroupType.PRIVATE);
if (userGroup.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
String errMsg = "Non admin '" + userId + "' attempting to create public group";
Logger.error(errMsg);
throw new PermissionException(errMsg);
}
Account account = accountDAO.getByEmail(userId);
Group group = new Group();
group.setUuid(Utils.generateUUID());
group.setLabel(userGroup.getLabel());
group.setDescription(userGroup.getDescription() == null ? "" : userGroup.getDescription());
group.setType(userGroup.getType());
group.setOwner(account);
group.setAutoJoin(userGroup.isAutoJoin());
group.setCreationTime(new Date());
group = dao.create(group);
// add local members
if (userGroup.getMembers() != null && !userGroup.getMembers().isEmpty()) {
for (AccountTransfer accountTransfer : userGroup.getMembers()) {
Account memberAccount = accountDAO.getByEmail(accountTransfer.getEmail());
if (memberAccount == null)
continue;
group.getMembers().add(memberAccount);
memberAccount.getGroups().add(group);
accountDAO.update(memberAccount);
}
}
// add remote members
for (RemoteUser remoteUser : userGroup.getRemoteMembers()) {
RegistryPartner partner = remoteUser.getPartner();
if (partner == null)
continue;
RemotePartner remotePartner = remotePartnerDAO.get(partner.getId());
if (remotePartner == null)
continue;
AccountTransfer accountTransfer = remoteUser.getUser();
if (accountTransfer == null || StringUtils.isEmpty(accountTransfer.getEmail()))
continue;
String email = accountTransfer.getEmail();
RemoteClientModel remoteClientModel = remoteClientModelDAO.getModel(email, remotePartner);
if (remoteClientModel == null) {
remoteClientModel = new RemoteClientModel();
remoteClientModel.setEmail(email);
remoteClientModel.setRemotePartner(remotePartner);
remoteClientModel = remoteClientModelDAO.create(remoteClientModel);
}
remoteClientModel.getGroups().add(group);
remoteClientModelDAO.update(remoteClientModel);
}
return group.toDataTransferObject();
}
use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.
the class Groups method get.
public Results<UserGroup> get(GroupType groupType, int offset, int limit) {
List<Group> groupList = dao.getGroupsByType(groupType, offset, limit);
Results<UserGroup> results = new Results<>();
results.setResultCount(dao.getGroupsByTypeCount(groupType));
for (Group group : groupList) {
UserGroup userGroup = group.toDataTransferObject();
long memberCount = dao.getMemberCount(group.getUuid());
userGroup.setMemberCount(memberCount);
results.getData().add(userGroup);
}
return results;
}
Aggregations