コード例 #1
0
 @RvdAuth
 @PUT
 @Path("{name}/rename")
 public Response renameProject(
     @PathParam("name") String projectName,
     @QueryParam("newName") String projectNewName,
     @QueryParam("ticket") String ticket)
     throws StorageException, ProjectDoesNotExist {
   if (!RvdUtils.isEmpty(projectName) && !RvdUtils.isEmpty(projectNewName)) {
     assertProjectAvailable(projectName);
     try {
       ProjectApplicationsApi applicationsApi =
           new ProjectApplicationsApi(servletContext, workspaceStorage, marshaler);
       applicationsApi.renameApplication(ticket, projectName, projectNewName);
       projectService.renameProject(projectName, projectNewName);
       return Response.ok().build();
     } catch (ProjectDirectoryAlreadyExists e) {
       logger.error(e.getMessage(), e);
       return Response.status(Status.CONFLICT).build();
     } catch (StorageException e) {
       return Response.status(Status.INTERNAL_SERVER_ERROR).build();
     } catch (ApplicationAlreadyExists e) {
       return Response.status(Status.CONFLICT).build();
     } catch (ApplicationsApiSyncException e) {
       logger.error(e.getMessage(), e);
       return Response.status(Status.INTERNAL_SERVER_ERROR).build();
     }
   } else return Response.status(Status.BAD_REQUEST).build();
 }
コード例 #2
0
  @RvdAuth
  @PUT
  @Path("{name}")
  public Response createProject(
      @PathParam("name") String name,
      @QueryParam("kind") String kind,
      @QueryParam("ticket") String ticket) {
    Principal loggedUser = securityContext.getUserPrincipal();
    ProjectApplicationsApi applicationsApi = null;

    logger.info("Creating project " + name);
    try {
      applicationsApi = new ProjectApplicationsApi(servletContext, workspaceStorage, marshaler);
      applicationsApi.createApplication(ticket, name, kind);
      ProjectState projectState = projectService.createProject(name, kind, loggedUser.getName());
      BuildService buildService = new BuildService(workspaceStorage);
      buildService.buildProject(name, projectState);
    } catch (ProjectAlreadyExists e) {
      logger.error(e.getMessage(), e);
      try {
        applicationsApi.rollbackCreateApplication(ticket, name);
      } catch (ApplicationsApiSyncException e1) {
        logger.error(e1.getMessage(), e1);
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
      }
      return Response.status(Status.CONFLICT).build();
    } catch (StorageException e) {
      logger.error(e.getMessage(), e);
      return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    } catch (InvalidServiceParameters e) {
      logger.error(e);
      return Response.status(Status.BAD_REQUEST).build();
    } catch (ApplicationAlreadyExists e) {
      logger.error(e.getMessage(), e);
      return Response.status(Status.CONFLICT).build();
    } catch (ApplicationsApiSyncException e) {
      logger.error(e.getMessage(), e);
      return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    } catch (UnsupportedEncodingException e) {
      logger.error(e.getMessage(), e);
      return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }

    return Response.ok().build();
  }
コード例 #3
0
  @RvdAuth
  @POST
  // @Path("{name}/archive")
  public Response importProjectArchive(
      @Context HttpServletRequest request, @QueryParam("ticket") String ticket) {
    logger.info("Importing project from raw archive");
    ProjectApplicationsApi applicationsApi = null;
    String projectName = null;

    try {
      if (request.getHeader("Content-Type") != null
          && request.getHeader("Content-Type").startsWith("multipart/form-data")) {
        Gson gson = new Gson();
        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iterator = upload.getItemIterator(request);

        JsonArray fileinfos = new JsonArray();

        while (iterator.hasNext()) {
          FileItemStream item = iterator.next();
          JsonObject fileinfo = new JsonObject();
          fileinfo.addProperty("fieldName", item.getFieldName());

          // is this a file part (talking about multipart requests, there might be parts that are
          // not actual files).
          // They will be ignored
          if (item.getName() != null) {
            String effectiveProjectName =
                projectService.importProjectFromArchive(item.openStream(), item.getName());
            // buildService.buildProject(effectiveProjectName);

            // Load project kind
            String projectString =
                FsProjectStorage.loadProjectString(effectiveProjectName, workspaceStorage);
            ProjectState state = marshaler.toModel(projectString, ProjectState.class);
            String projectKind = state.getHeader().getProjectKind();
            projectName = effectiveProjectName;

            // Create application
            applicationsApi =
                new ProjectApplicationsApi(servletContext, workspaceStorage, marshaler);
            applicationsApi.createApplication(ticket, effectiveProjectName, projectKind);

            fileinfo.addProperty("name", item.getName());
            fileinfo.addProperty("projectName", effectiveProjectName);
          }
          if (item.getName() == null) {
            logger.warn("non-file part found in upload");
            fileinfo.addProperty("value", read(item.openStream()));
          }
          fileinfos.add(fileinfo);
        }
        return Response.ok(gson.toJson(fileinfos), MediaType.APPLICATION_JSON).build();
      } else {
        String json_response = "{\"result\":[{\"size\":" + size(request.getInputStream()) + "}]}";
        return Response.ok(json_response, MediaType.APPLICATION_JSON).build();
      }
    } catch (StorageException e) {
      logger.warn(e, e);
      logger.debug(e, e);
      return buildErrorResponse(Status.BAD_REQUEST, RvdResponse.Status.ERROR, e);
    } catch (ApplicationAlreadyExists e) {
      logger.warn(e, e);
      logger.debug(e, e);
      try {
        applicationsApi.rollbackCreateApplication(ticket, projectName);
      } catch (ApplicationsApiSyncException e1) {
        logger.error(e1.getMessage(), e1);
        return buildErrorResponse(Status.INTERNAL_SERVER_ERROR, RvdResponse.Status.ERROR, e);
      }
      return buildErrorResponse(Status.CONFLICT, RvdResponse.Status.ERROR, e);
    } catch (Exception e /* TODO - use a more specific type !!! */) {
      logger.error(e.getMessage(), e);
      return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
  }