use of io.hops.hopsworks.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class ProjectService method updateProject.
@PUT
@Path("{projectId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
public Response updateProject(ProjectDTO projectDTO, @PathParam("projectId") Integer id, @Context SecurityContext sc) throws ProjectException, DatasetException, HopsSecurityException, ServiceException, FeaturestoreException, OpenSearchException, SchemaException, KafkaException, ProvenanceException, IOException, UserException {
RESTApiJsonResponse json = new RESTApiJsonResponse();
Users user = jWTHelper.getUserPrincipal(sc);
Project project = projectController.findProjectById(id);
boolean updated = false;
if (projectController.updateProjectDescription(project, projectDTO.getDescription(), user)) {
json.setSuccessMessage(ResponseMessages.PROJECT_DESCRIPTION_CHANGED);
updated = true;
}
if (projectController.updateProjectRetention(project, projectDTO.getRetentionPeriod(), user)) {
json.setSuccessMessage(json.getSuccessMessage() + "\n" + ResponseMessages.PROJECT_RETENTON_CHANGED);
updated = true;
}
if (!projectDTO.getServices().isEmpty()) {
// Create dfso here and pass them to the different controllers
DistributedFileSystemOps dfso = dfs.getDfsOps();
DistributedFileSystemOps udfso = dfs.getDfsOps(hdfsUsersBean.getHdfsUserName(project, user));
for (String s : projectDTO.getServices()) {
ProjectServiceEnum se = null;
se = ProjectServiceEnum.valueOf(s.toUpperCase());
ProvTypeDTO projectMetaStatus = fsProvenanceController.getProjectProvType(user, project);
List<Future<?>> serviceFutureList = projectController.addService(project, se, user, dfso, udfso, projectMetaStatus);
if (serviceFutureList != null) {
// Wait for the futures
for (Future f : serviceFutureList) {
try {
f.get();
} catch (InterruptedException | ExecutionException e) {
throw new ServiceException(RESTCodes.ServiceErrorCode.SERVICE_GENERIC_ERROR, Level.SEVERE, "service: " + s, e.getMessage(), e);
}
}
// Service successfully enabled
json.setSuccessMessage(json.getSuccessMessage() + "\n" + ResponseMessages.PROJECT_SERVICE_ADDED + s);
updated = true;
}
}
// close dfsos
if (dfso != null) {
dfso.close();
}
if (udfso != null) {
dfs.closeDfsClient(udfso);
}
}
if (!updated) {
json.setSuccessMessage(ResponseMessages.NOTHING_TO_UPDATE);
}
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.CREATED).entity(json).build();
}
use of io.hops.hopsworks.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class ProjectService method createProject.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response createProject(ProjectDTO projectDTO, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, GenericException, KafkaException, ProjectException, UserException, ServiceException, HopsSecurityException, FeaturestoreException, OpenSearchException, SchemaException, IOException {
Users user = jWTHelper.getUserPrincipal(sc);
projectController.createProject(projectDTO, user, req.getSession().getId());
RESTApiJsonResponse json = new RESTApiJsonResponse();
StringBuilder message = new StringBuilder();
message.append(ResponseMessages.PROJECT_CREATED);
message.append("<br>You have ").append(user.getMaxNumProjects() - user.getNumCreatedProjects()).append(" project(s) left that you can create");
json.setSuccessMessage(message.toString());
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.CREATED).entity(json).build();
}
use of io.hops.hopsworks.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class ProjectService method checkProjectAccess.
@GET
@Path("{projectId}/check")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
public Response checkProjectAccess(@PathParam("projectId") Integer id, @Context SecurityContext sc) {
RESTApiJsonResponse json = new RESTApiJsonResponse();
json.setData(id);
return Response.ok(json).build();
}
use of io.hops.hopsworks.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class RequestService method requestJoin.
@POST
@Path("/join")
@Produces(MediaType.APPLICATION_JSON)
public Response requestJoin(RequestDTO requestDTO, @Context SecurityContext sc) throws ProjectException {
RESTApiJsonResponse json = new RESTApiJsonResponse();
if (requestDTO == null || requestDTO.getProjectId() == null) {
throw new IllegalArgumentException("requestDTO wast not provided or was incomplete.");
}
// should be removed when users and user merg.
Users user = jWTHelper.getUserPrincipal(sc);
Project project = projectFacade.find(requestDTO.getProjectId());
if (project == null) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE);
}
ProjectTeam projectTeam = projectTeamFacade.findByPrimaryKey(project, user);
if (projectTeam != null) {
throw new ProjectException(RESTCodes.ProjectErrorCode.TEAM_MEMBER_ALREADY_EXISTS, Level.FINE);
}
// email body
String msg = "Hi " + project.getOwner().getFname() + " " + project.getOwner().getLname() + ", \n\n" + user.getFname() + " " + user.getLname() + " wants to join a project you own. \n\n" + "Project name: " + project.getName() + "\n";
if (!Strings.isNullOrEmpty(requestDTO.getMessageContent())) {
msg += "Attached message: " + requestDTO.getMessageContent() + "\n";
}
msg += "After logging in to Hopsworks go to : /project" + project.getId() + " and go to members tab " + "if you want to add this person as a member in your project. \n";
Users from = user;
Users to = userFacade.findByEmail(project.getOwner().getEmail());
String message = "Hi " + to.getFname() + "<br>" + "I would like to join a project you own. <br>" + "Project name: " + project.getName() + "<br>";
if (!Strings.isNullOrEmpty(requestDTO.getMessageContent())) {
message += requestDTO.getMessageContent();
}
String preview = from.getFname() + " would like to join a project you own.";
String subject = "Project join request.";
String path = "project/" + project.getId();
// to, from, msg, requested path
messageBean.send(to, from, subject, preview, message, path);
try {
emailBean.sendEmail(project.getOwner().getEmail(), RecipientType.TO, "Join request for project " + project.getName(), msg);
} catch (MessagingException ex) {
json.setErrorMsg("Could not send e-mail to " + project.getOwner().getEmail());
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.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class MessageService method countUnreadMessagesByUser.
@GET
@Path("countUnread")
@Produces(MediaType.APPLICATION_JSON)
public Response countUnreadMessagesByUser(@Context SecurityContext sc) {
RESTApiJsonResponse json = new RESTApiJsonResponse();
Users user = jWTHelper.getUserPrincipal(sc);
Long unread = msgFacade.countUnreadMessagesTo(user);
json.setData(unread);
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
Aggregations