Search in sources :

Example 21 with RESTApiJsonResponse

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();
}
Also used : DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) Users(io.hops.hopsworks.persistence.entity.user.Users) ProjectServiceEnum(io.hops.hopsworks.persistence.entity.project.service.ProjectServiceEnum) Project(io.hops.hopsworks.persistence.entity.project.Project) ServiceException(io.hops.hopsworks.exceptions.ServiceException) RESTApiJsonResponse(io.hops.hopsworks.api.util.RESTApiJsonResponse) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) ProvTypeDTO(io.hops.hopsworks.common.provenance.core.dto.ProvTypeDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 22 with RESTApiJsonResponse

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();
}
Also used : RESTApiJsonResponse(io.hops.hopsworks.api.util.RESTApiJsonResponse) Users(io.hops.hopsworks.persistence.entity.user.Users) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 23 with RESTApiJsonResponse

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();
}
Also used : RESTApiJsonResponse(io.hops.hopsworks.api.util.RESTApiJsonResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 24 with RESTApiJsonResponse

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();
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) MessagingException(javax.mail.MessagingException) RESTApiJsonResponse(io.hops.hopsworks.api.util.RESTApiJsonResponse) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 25 with RESTApiJsonResponse

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();
}
Also used : RESTApiJsonResponse(io.hops.hopsworks.api.util.RESTApiJsonResponse) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

RESTApiJsonResponse (io.hops.hopsworks.api.util.RESTApiJsonResponse)43 Path (javax.ws.rs.Path)35 Produces (javax.ws.rs.Produces)32 Users (io.hops.hopsworks.persistence.entity.user.Users)24 POST (javax.ws.rs.POST)23 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)14 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)11 Project (io.hops.hopsworks.persistence.entity.project.Project)11 ProjectException (io.hops.hopsworks.exceptions.ProjectException)9 Consumes (javax.ws.rs.Consumes)8 GET (javax.ws.rs.GET)7 DELETE (javax.ws.rs.DELETE)6 JWTNotRequired (io.hops.hopsworks.api.filter.JWTNotRequired)4 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)4 UserException (io.hops.hopsworks.exceptions.UserException)3 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)3 JsonResponse (io.hops.hopsworks.restutils.JsonResponse)3 ApiOperation (io.swagger.annotations.ApiOperation)3 RolesAllowed (javax.annotation.security.RolesAllowed)3 QrCode (io.hops.hopsworks.common.user.QrCode)2