use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class AnnotationResource method rebuildAnnotations.
@PUT
@Path("/indexes")
public Response rebuildAnnotations() {
String userId = requireUserId();
Annotations annotations = new Annotations(userId);
try {
annotations.rebuild();
} catch (PermissionException pe) {
Logger.error(pe);
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
return super.respond(true);
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class AnnotationResource method curate.
/**
* Curate available annotations to include or exclude them from auto-annotation feature
*
* @param list list of annotations each with specified curate
*/
@PUT
@Produces(MediaType.APPLICATION_JSON)
public Response curate(List<DNAFeature> list) {
String userId = requireUserId();
Annotations annotations = new Annotations(userId);
try {
final Type fooType = new TypeToken<ArrayList<DNAFeature>>() {
}.getType();
final Gson gson = new GsonBuilder().create();
final ArrayList<DNAFeature> features = gson.fromJson(gson.toJsonTree(list), fooType);
annotations.curate(features);
return super.respond(true);
} catch (PermissionException e) {
Logger.error(e);
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class ApiKeyResource method getApiKeys.
/**
* retrieves list of api keys created by user
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getApiKeys(@DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("15") @QueryParam("limit") int limit, @DefaultValue("true") @QueryParam("asc") boolean asc, @DefaultValue("creationTime") @QueryParam("sort") String sort, @DefaultValue("false") @QueryParam("getAll") boolean getAll) {
String userId = requireUserId();
UserApiKeys apiKeys = new UserApiKeys(userId);
try {
return super.respond(apiKeys.getKeys(limit, offset, sort, asc, getAll));
} catch (PermissionException pe) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class GroupController method deleteGroup.
public boolean deleteGroup(String userIdStr, long groupId) {
Account account = DAOFactory.getAccountDAO().getByEmail(userIdStr);
Group group = dao.get(groupId);
if (group == null)
return false;
if (group.getType() == GroupType.PUBLIC && account.getType() != AccountType.ADMIN) {
String errMsg = "Non admin " + account.getEmail() + " attempting to delete public group";
Logger.error(errMsg);
throw new PermissionException(errMsg);
}
if (group.getMembers() != null) {
for (Account member : group.getMembers()) {
accountController.removeMemberFromGroup(group.getId(), member.getEmail());
}
}
DAOFactory.getPermissionDAO().clearPermissions(group);
dao.delete(group);
return true;
}
use of org.jbei.ice.lib.access.PermissionException 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();
}
Aggregations