use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam in project hopsworks by logicalclocks.
the class DelaService method getContentsForUser.
@GET
@Path("/transfers")
@Produces(MediaType.APPLICATION_JSON)
public Response getContentsForUser(@Context SecurityContext sc, @QueryParam("filter") TransfersFilter filter) throws DelaException {
if (!filter.equals(TransfersFilter.USER)) {
throw new DelaException(RESTCodes.DelaErrorCode.ILLEGAL_ARGUMENT, Level.FINE, DelaException.Source.LOCAL, "not handling filter value:" + filter);
}
Users user = jWTHelper.getUserPrincipal(sc);
List<ProjectTeam> teams = projectCtrl.findProjectByUser(user.getEmail());
List<Integer> projectIds = new LinkedList<>();
for (ProjectTeam t : teams) {
projectIds.add(t.getProject().getId());
}
HopsContentsSummaryJSON.Contents resp = delaTransferCtrl.getContents(projectIds);
List<UserContentsSummaryJSON> userContents = new ArrayList<>();
Iterator<Map.Entry<Integer, ElementSummaryJSON[]>> it = resp.getContents().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Integer, ElementSummaryJSON[]> n = it.next();
userContents.add(new UserContentsSummaryJSON(n.getKey(), n.getValue()));
}
GenericEntity<List<UserContentsSummaryJSON>> userContentsList = new GenericEntity<List<UserContentsSummaryJSON>>(userContents) {
};
return success(userContentsList);
}
use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam in project hopsworks by logicalclocks.
the class ModelsBuilder method buildFilter.
private Pair<ProvStateParamBuilder, ModelRegistryDTO> buildFilter(Project project, Project modelRegistryProject, Set<? extends AbstractFacade.FilterBy> filters) throws GenericException, ProvenanceException, DatasetException {
ProvStateParamBuilder provFilesParamBuilder = new ProvStateParamBuilder();
if (filters != null) {
Users filterUser = null;
Project filterUserProject = project;
for (AbstractFacade.FilterBy filterBy : filters) {
if (filterBy.getParam().compareToIgnoreCase(Filters.NAME_EQ.name()) == 0) {
provFilesParamBuilder.filterByXAttr(MODEL_SUMMARY_XATTR_NAME + ".name", filterBy.getValue());
} else if (filterBy.getParam().compareToIgnoreCase(Filters.NAME_LIKE.name()) == 0) {
provFilesParamBuilder.filterLikeXAttr(MODEL_SUMMARY_XATTR_NAME + ".name", filterBy.getValue());
} else if (filterBy.getParam().compareToIgnoreCase(Filters.VERSION.name()) == 0) {
provFilesParamBuilder.filterByXAttr(MODEL_SUMMARY_XATTR_NAME + ".version", filterBy.getValue());
} else if (filterBy.getParam().compareToIgnoreCase(Filters.ID_EQ.name()) == 0) {
provFilesParamBuilder.filterByXAttr(MODEL_SUMMARY_XATTR_NAME + ".id", filterBy.getValue());
} else if (filterBy.getParam().compareToIgnoreCase(Filters.USER.name()) == 0) {
try {
filterUser = userFacade.find(Integer.parseInt(filterBy.getValue()));
} catch (NumberFormatException e) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "expected int user id, found: " + filterBy.getValue());
}
} else if (filterBy.getParam().compareToIgnoreCase(Filters.USER_PROJECT.name()) == 0) {
try {
filterUserProject = projectFacade.find(Integer.parseInt(filterBy.getValue()));
} catch (NumberFormatException e) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "expected int user project id, found: " + filterBy.getValue());
}
} else {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "Filter by - found: " + filterBy.getParam() + " expected:" + EnumSet.allOf(Filters.class));
}
}
if (filterUser != null) {
ProjectTeam member = projectTeamFacade.findByPrimaryKey(filterUserProject, filterUser);
if (member == null) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "Selected user: " + filterUser.getUid() + " is not part of project:" + filterUserProject.getId());
}
String hdfsUserStr = hdfsUsersController.getHdfsUserName(filterUserProject, filterUser);
HdfsUsers hdfsUsers = hdfsUsersFacade.findByName(hdfsUserStr);
provFilesParamBuilder.filterByField(ProvStateParser.FieldsP.USER_ID, hdfsUsers.getId().toString());
}
}
ModelRegistryDTO modelRegistryDTO = modelsController.getModelRegistry(modelRegistryProject);
provFilesParamBuilder.filterByField(ProvStateParser.FieldsP.PROJECT_I_ID, modelRegistryDTO.getParentProject().getInode().getId()).filterByField(ProvStateParser.FieldsP.DATASET_I_ID, modelRegistryDTO.getDatasetInodeId());
return Pair.with(provFilesParamBuilder, modelRegistryDTO);
}
use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam in project hopsworks by logicalclocks.
the class RequestService method requestAccess.
@POST
@Path("/access")
@Produces(MediaType.APPLICATION_JSON)
public Response requestAccess(RequestDTO requestDTO, @Context SecurityContext sc) throws DatasetException, ProjectException {
RESTApiJsonResponse json = new RESTApiJsonResponse();
if (requestDTO == null || requestDTO.getInodeId() == null || requestDTO.getProjectId() == null) {
throw new IllegalArgumentException("requestDTO was not provided or was incomplete!");
}
Users user = jWTHelper.getUserPrincipal(sc);
Inode inode = inodes.findById(requestDTO.getInodeId());
// requested project
Project proj = datasetCtrl.getOwningProject(inode);
Dataset ds = datasetFacade.findByProjectAndInode(proj, inode);
// requesting project
Project project = projectFacade.find(requestDTO.getProjectId());
Dataset dsInRequesting = datasetFacade.findByProjectAndInode(project, inode);
if (dsInRequesting != null) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DESTINATION_EXISTS, Level.INFO);
}
ProjectTeam projectTeam = projectTeamFacade.findByPrimaryKey(project, user);
ProjectTeam projTeam = projectTeamFacade.findByPrimaryKey(proj, user);
if (projTeam != null && proj.equals(project)) {
throw new ProjectException(RESTCodes.ProjectErrorCode.TEAM_MEMBER_ALREADY_EXISTS, Level.FINE);
}
DatasetRequest dsRequest = datasetRequest.findByProjectAndDataset(project, ds);
// email body
String msg = "Hi " + proj.getOwner().getFname() + " " + proj.getOwner().getLname() + ", \n\n" + user.getFname() + " " + user.getLname() + " wants access to a dataset in a project you own. \n\n" + "Dataset name: " + ds.getInode().getInodePK().getName() + "\n" + "Project name: " + proj.getName() + "\n";
if (!Strings.isNullOrEmpty(requestDTO.getMessageContent())) {
msg += "Attached message: " + requestDTO.getMessageContent() + "\n";
}
msg += "After logging in to Hopsworks go to : /project/" + proj.getId() + "/datasets " + " if you want to share this dataset. \n";
// or the prior request is from a data owner do nothing.
if (dsRequest != null && (dsRequest.getProjectTeam().getTeamRole().equals(projectTeam.getTeamRole()) || dsRequest.getProjectTeam().getTeamRole().equals(AllowedProjectRoles.DATA_OWNER))) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_REQUEST_EXISTS, Level.FINE);
} else if (dsRequest != null && projectTeam.getTeamRole().equals(AllowedProjectRoles.DATA_OWNER)) {
dsRequest.setProjectTeam(projectTeam);
dsRequest.setMessageContent(requestDTO.getMessageContent());
datasetRequest.merge(dsRequest);
} else {
Users to = userFacade.findByEmail(proj.getOwner().getEmail());
String message = "Hi " + to.getFname() + "<br>" + "I would like to request access to a dataset in a project you own. <br>" + "Project name: " + proj.getName() + "<br>" + "Dataset name: " + ds.getInode().getInodePK().getName() + "<br>" + "To be shared with my project: " + project.getName() + ".<br>" + "Thank you in advance.";
String preview = user.getFname() + " would like to have access to a dataset in a project you own.";
String subject = Settings.MESSAGE_DS_REQ_SUBJECT;
String path = "project/" + proj.getId() + "/datasets";
// to, from, msg, requested path
Message newMsg = new Message(user, to, null, message, true, false);
newMsg.setPath(path);
newMsg.setSubject(subject);
newMsg.setPreview(preview);
messageBean.send(newMsg);
dsRequest = new DatasetRequest(ds, projectTeam, requestDTO.getMessageContent(), newMsg);
try {
datasetRequest.persistDataset(dsRequest);
} catch (Exception ex) {
messageBean.remove(newMsg);
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_REQUEST_ERROR, Level.WARNING, ex.getMessage(), null, ex);
}
}
try {
emailBean.sendEmail(proj.getOwner().getEmail(), RecipientType.TO, "Access request for dataset " + ds.getInode().getInodePK().getName(), msg);
} catch (MessagingException ex) {
json.setErrorMsg("Could not send e-mail to " + project.getOwner().getEmail());
datasetRequest.remove(dsRequest);
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
json.setSuccessMessage("Request sent successfully.");
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam in project hopsworks by logicalclocks.
the class ExperimentsBuilder method buildFilter.
private Pair<ProvStateParamBuilder, Map<Long, ExperimentsEndpointDTO>> buildFilter(Project project, Set<? extends AbstractFacade.FilterBy> filters) throws ProvenanceException, GenericException, DatasetException {
ProvStateParamBuilder provFilesParamBuilder = new ProvStateParamBuilder();
Map<Long, ExperimentsEndpointDTO> selectedEndpoints = new HashMap<>();
if (filters != null) {
Users filterUser = null;
Project filterUserProject = project;
for (AbstractFacade.FilterBy filterBy : filters) {
if (filterBy.getParam().compareToIgnoreCase(Filters.ENDPOINT_ID.name()) == 0) {
ExperimentsEndpointDTO endpoint = verifyExperimentsEndpoint(project, filterBy.getValue());
selectedEndpoints.put(endpoint.getParentProject().getInode().getId(), endpoint);
} else if (filterBy.getParam().compareToIgnoreCase(Filters.NAME_LIKE.name()) == 0) {
provFilesParamBuilder.filterLikeXAttr(EXPERIMENT_SUMMARY_XATTR_NAME + ".name", filterBy.getValue());
} else if (filterBy.getParam().compareToIgnoreCase(Filters.NAME_EQ.name()) == 0) {
provFilesParamBuilder.filterByXAttr(EXPERIMENT_SUMMARY_XATTR_NAME + ".name", filterBy.getValue());
} else if (filterBy.getParam().compareToIgnoreCase(Filters.DATE_START_LT.name()) == 0) {
Long timestamp = getDate(filterBy.getField(), filterBy.getValue()).getTime();
provFilesParamBuilder.filterByField(ProvStateParser.FieldsPF.CREATE_TIMESTAMP_LT, timestamp);
} else if (filterBy.getParam().compareToIgnoreCase(Filters.DATE_START_GT.name()) == 0) {
Long timestamp = getDate(filterBy.getField(), filterBy.getValue()).getTime();
provFilesParamBuilder.filterByField(ProvStateParser.FieldsPF.CREATE_TIMESTAMP_GT, timestamp);
} else if (filterBy.getParam().compareToIgnoreCase(Filters.USER.name()) == 0) {
try {
filterUser = userFacade.find(Integer.parseInt(filterBy.getValue()));
} catch (NumberFormatException e) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "expected int user id, found: " + filterBy.getValue());
}
} else if (filterBy.getParam().compareToIgnoreCase(Filters.USER_PROJECT.name()) == 0) {
try {
filterUserProject = projectFacade.find(Integer.parseInt(filterBy.getValue()));
} catch (NumberFormatException e) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "expected int user project id, found: " + filterBy.getValue());
}
} else if (filterBy.getParam().compareToIgnoreCase(Filters.STATE.name()) == 0) {
provFilesParamBuilder.filterLikeXAttr(EXPERIMENT_SUMMARY_XATTR_NAME + ".state", filterBy.getValue());
} else if (filterBy.getParam().compareToIgnoreCase(Filters.ID_EQ.name()) == 0) {
provFilesParamBuilder.filterByXAttr(EXPERIMENT_SUMMARY_XATTR_NAME + ".id", filterBy.getValue());
} else {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "Filter by - found: " + filterBy.getParam() + " expected:" + EnumSet.allOf(Filters.class));
}
}
if (filterUser != null) {
ProjectTeam member = projectTeamFacade.findByPrimaryKey(filterUserProject, filterUser);
if (member == null) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "Selected user: " + filterUser.getUid() + " is not part of project:" + filterUserProject.getId());
}
String hdfsUserStr = hdfsUsersController.getHdfsUserName(filterUserProject, filterUser);
HdfsUsers hdfsUsers = hdfsUsersFacade.findByName(hdfsUserStr);
provFilesParamBuilder.filterByField(ProvStateParser.FieldsP.USER_ID, hdfsUsers.getId().toString());
}
}
// an endpoint always has to be selected, if none provided, then all accessible endpoints are used
if (selectedEndpoints.isEmpty()) {
for (ExperimentsEndpointDTO endpoint : experimentsController.getExperimentsEndpoints(project)) {
selectedEndpoints.put(endpoint.getParentProject().getInode().getId(), endpoint);
}
}
for (ExperimentsEndpointDTO endpoint : selectedEndpoints.values()) {
provFilesParamBuilder.filterByField(ProvStateParser.FieldsP.PROJECT_I_ID, endpoint.getParentProject().getInode().getId()).filterByField(ProvStateParser.FieldsP.DATASET_I_ID, endpoint.getDatasetInodeId());
}
return Pair.with(provFilesParamBuilder, selectedEndpoints);
}
use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam in project hopsworks by logicalclocks.
the class ProjectMembersService method getDatasetMembers.
@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@Path("/dataset/{name}")
public Response getDatasetMembers(@PathParam("name") String dsName, @QueryParam("type") DatasetType datasetType) throws ProjectException, DatasetException {
Project project = projectController.findProjectById(this.projectId);
String path = Utils.getProjectPath(project.getName()) + dsName;
DatasetPath dp = datasetHelper.getDatasetPath(project, path, datasetType);
Collection<ProjectTeam> membersCol = accessCtrl.getExtendedMembers(dp.getDataset());
GenericEntity<Collection<ProjectTeam>> members = new GenericEntity<Collection<ProjectTeam>>(membersCol) {
};
return Response.ok().entity(members).build();
}
Aggregations