/* (non-Javadoc)
   * @see uk.ac.ox.oucs.oxam.logic.PaperFileService#deposit(uk.ac.ox.oucs.oxam.logic.PaperFile, uk.ac.ox.oucs.oxam.logic.Callback)
   */
  public void deposit(PaperFile paperFile, InputStream in) {
    PaperFileImpl impl = castToImpl(paperFile);
    String path = impl.getPath();
    ContentResourceEdit resource = null;
    try {

      try {
        contentHostingService.checkResource(path);
        resource = contentHostingService.editResource(path);
        // Ignore PermissionException, IdUnusedException, TypeException
        // As they are too serious to continue.
      } catch (IdUnusedException iue) {
        // Will attempt to create containing folders.

        resource = contentHostingService.addResource(path);
        // Like the basename function.
        String filename = StringUtils.substringAfterLast(path, "/");
        ResourceProperties props = resource.getPropertiesEdit();
        props.addProperty(ResourceProperties.PROP_DISPLAY_NAME, filename);
        resource.setContentType(mimeTypes.getContentType(filename));
      }
      resource.setContent(in);
      contentHostingService.commitResource(resource, NotificationService.NOTI_NONE);
      LOG.debug("Sucessfully copied file to: " + path);
    } catch (OverQuotaException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ServerOverloadException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (PermissionException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InUseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TypeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IdUsedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IdInvalidException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InconsistentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      // Close the stream here as this is where it's created.
      if (resource.isActiveEdit()) {
        contentHostingService.cancelResource(resource);
      }
    }
  }
Esempio n. 2
0
  @WebMethod
  @Path("/undeleteAssignments")
  @Produces("text/plain")
  @GET
  public String undeleteAssignments(
      @WebParam(name = "sessionId", partName = "sessionId") @QueryParam("sessionId")
          String sessionId,
      @WebParam(name = "context", partName = "context") @QueryParam("context") String context) {
    try {
      // establish the session
      Session s = establishSession(sessionId);

      Iterator assingments = assignmentService.getAssignmentsForContext(context);
      while (assingments.hasNext()) {
        Assignment ass = (Assignment) assingments.next();
        ResourceProperties rp = ass.getProperties();

        try {
          String deleted = rp.getProperty(ResourceProperties.PROP_ASSIGNMENT_DELETED);

          LOG.info("Assignment " + ass.getTitle() + " deleted status: " + deleted);
          if (deleted != null) {
            AssignmentEdit ae = assignmentService.editAssignment(ass.getId());
            ResourcePropertiesEdit rpe = ae.getPropertiesEdit();
            LOG.info("undeleting" + ass.getTitle() + " for site " + context);
            rpe.removeProperty(ResourceProperties.PROP_ASSIGNMENT_DELETED);

            assignmentService.commitEdit(ae);
          }
        } catch (IdUnusedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (PermissionException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (InUseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } catch (Exception e) {
      LOG.error("WS undeleteAssignments(): " + e.getClass().getName() + " : " + e.getMessage());
      return e.getClass().getName() + " : " + e.getMessage();
    }

    return "success";
  }