public static org.sakaiproject.content.api.ContentResource addResource(
      java.lang.String param0,
      java.lang.String param1,
      int param2,
      java.lang.String param3,
      byte[] param4,
      org.sakaiproject.entity.api.ResourceProperties param5,
      java.util.Collection param6,
      boolean param7,
      org.sakaiproject.time.api.Time param8,
      org.sakaiproject.time.api.Time param9,
      int param10)
      throws org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdInvalidException,
          org.sakaiproject.exception.InconsistentException,
          org.sakaiproject.exception.OverQuotaException,
          org.sakaiproject.exception.ServerOverloadException,
          org.sakaiproject.exception.IdUniquenessException,
          org.sakaiproject.exception.IdLengthException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.addResource(
        param0, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10);
  }
  public static java.util.List findResources(
      String type, String primaryMimeType, String subMimeType) {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.findResources(type, primaryMimeType, subMimeType);
  }
  public static Collection<ContentResource> getContextResourcesOfType(
      String resourceType, Set<String> contextIds) {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.getContextResourcesOfType(resourceType, contextIds);
  }
  public static java.util.Comparator newContentHostingComparator(
      java.lang.String param0, boolean param1) {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.newContentHostingComparator(param0, param1);
  }
  /**
   * @param id id of the resource to set the UUID for
   * @param uuid the new UUID of the resource
   * @throws org.sakaiproject.exception.IdInvalidException if the given resource already has a UUID
   *     set
   */
  public static void setUuid(java.lang.String id, java.lang.String uuid)
      throws org.sakaiproject.exception.IdInvalidException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return;

    service.setUuid(id, uuid);
  }
  public static void removeDeletedResource(String resourceId)
      throws PermissionException, IdUnusedException, TypeException, InUseException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return;

    service.removeDeletedResource(resourceId);
  }
  /**
   * Retrieve a collection of ContentResource objects pf a particular resource-type. The collection
   * will contain no more than the number of items specified as the pageSize, where pageSize is a
   * non-negative number less than or equal to 1028. The resources will be selected in ascending
   * order by resource-id. If the resources of the specified resource-type in the
   * ContentHostingService in ascending order by resource-id are indexed from 0 to M and this method
   * is called with parameters of N for pageSize and I for page, the resources returned will be
   * those with indexes (I*N) through ((I+1)*N - 1). For example, if pageSize is 1028 and page is 0,
   * the resources would be those with indexes of 0 to 1027. This method finds the resources the
   * current user has access to from a "page" of all resources of the specified type. If that page
   * contains no resources the current user has access to, the method returns an empty collection.
   * If the page does not exist (i.e. there are fewer than ((page+1)*page_size) resources of the
   * specified type), the method returns null.
   *
   * @param resourceType
   * @param pageSize
   * @param page
   * @return
   */
  public static Collection<ContentResource> getResourcesOfType(
      String resourceType, int pageSize, int page) {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.getResourcesOfType(resourceType, pageSize, page);
  }
  public static void removeResource(org.sakaiproject.content.api.ContentResourceEdit param0)
      throws org.sakaiproject.exception.PermissionException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return;

    service.removeResource(param0);
  }
  public static void checkResource(java.lang.String param0)
      throws org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdUnusedException, org.sakaiproject.exception.TypeException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return;

    service.checkResource(param0);
  }
  public static void removeCollection(java.lang.String param0)
      throws org.sakaiproject.exception.IdUnusedException, org.sakaiproject.exception.TypeException,
          org.sakaiproject.exception.PermissionException, org.sakaiproject.exception.InUseException,
          org.sakaiproject.exception.ServerOverloadException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return;

    service.removeCollection(param0);
  }
  public static org.sakaiproject.content.api.ContentCollection getCollection(
      java.lang.String param0)
      throws org.sakaiproject.exception.IdUnusedException, org.sakaiproject.exception.TypeException,
          org.sakaiproject.exception.PermissionException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.getCollection(param0);
  }
  public static void restoreResource(String resourceId)
      throws PermissionException, IdUsedException, IdUnusedException, IdInvalidException,
          InconsistentException, OverQuotaException, ServerOverloadException, TypeException,
          InUseException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return;

    service.restoreResource(resourceId);
  }
  public static void commitResource(org.sakaiproject.content.api.ContentResourceEdit param0)
      throws org.sakaiproject.exception.OverQuotaException,
          org.sakaiproject.exception.ServerOverloadException,
          org.sakaiproject.antivirus.api.VirusFoundException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return;

    service.commitResource(param0);
  }
Example #14
0
  private void addFolder(ContentCollection n, ResourceDefinition rp, int depth)
      throws SDataException {
    put("available", n.isAvailable());
    put("hidden", n.isHidden());
    if (!n.isHidden()) {
      Time releaseDate = n.getReleaseDate();
      if (releaseDate != null) {
        put("releaseDate", releaseDate.getTime());
      }
      Time retractDate = n.getRetractDate();
      if (retractDate != null) {
        put("retractDate", retractDate.getTime());
      }
    }

    ContentCollection cc = (ContentCollection) n;
    put("members", cc.getMemberCount());
    if (depth >= 0) {

      Map<String, Object> nodes = new HashMap<String, Object>();
      // list of IDs
      List<?> l = cc.getMembers();

      int i = 0;
      for (int k = 0; k < l.size(); k++) {
        String memberID = (String) l.get(k);
        ContentEntity cn = null;
        try {
          cn = contentHostingService.getResource(memberID);
        } catch (Exception idex) {
          try {
            String collectionPath = memberID;
            if (!collectionPath.endsWith("/")) {
              collectionPath = collectionPath + "/";
            }
            cn = contentHostingService.getCollection(collectionPath);
          } catch (Exception ex) {

          }
        }
        if (cn != null) {

          try {
            Map<String, Object> m = new CHSNodeMap(cn, depth, rp);
            m.put("position", String.valueOf(i));
            nodes.put(getName(cn), m);
          } catch (SDataAccessException sdae) {
            // hide the item from the list
            continue;
          }
        }
        i++;
      }
      put("nitems", nodes.size());
      put("items", nodes);
    }
  }
  public static org.sakaiproject.entity.api.ResourceProperties getProperties(
      java.lang.String param0)
      throws org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdUnusedException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.getProperties(param0);
  }
  public static void removeCollection(org.sakaiproject.content.api.ContentCollectionEdit param0)
      throws org.sakaiproject.exception.TypeException,
          org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.InconsistentException,
          org.sakaiproject.exception.ServerOverloadException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return;

    service.removeCollection(param0);
  }
  public static java.lang.String archiveResources(
      java.util.List param0,
      org.w3c.dom.Document param1,
      java.util.Stack param2,
      java.lang.String param3) {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.archiveResources(param0, param1, param2, param3);
  }
  /* (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);
      }
    }
  }
  /**
   * @param param0
   * @param param1
   * @return
   * @throws org.sakaiproject.exception.IdUsedException
   * @throws org.sakaiproject.exception.IdInvalidException
   * @throws org.sakaiproject.exception.PermissionException
   * @throws org.sakaiproject.exception.InconsistentException
   * @deprecated Suggest use of {@link #addCollection(String)} followed by {@link
   *     #getProperties(String)}, and {@link #commitCollection(ContentCollectionEdit)}
   */
  public static org.sakaiproject.content.api.ContentCollection addCollection(
      java.lang.String param0, org.sakaiproject.entity.api.ResourceProperties param1)
      throws org.sakaiproject.exception.IdUsedException,
          org.sakaiproject.exception.IdInvalidException,
          org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.InconsistentException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.addCollection(param0, param1);
  }
  public static org.sakaiproject.content.api.ContentResourceEdit addResource(
      java.lang.String param0)
      throws org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdUsedException, org.sakaiproject.exception.IdInvalidException,
          org.sakaiproject.exception.InconsistentException,
          org.sakaiproject.exception.ServerOverloadException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.addResource(param0);
  }
  public static String copy(java.lang.String param0, java.lang.String param1)
      throws org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdUnusedException, org.sakaiproject.exception.TypeException,
          org.sakaiproject.exception.InUseException, org.sakaiproject.exception.OverQuotaException,
          org.sakaiproject.exception.IdUsedException,
          org.sakaiproject.exception.ServerOverloadException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.copy(param0, param1);
  }
  public static org.sakaiproject.entity.api.ResourceProperties removeProperty(
      java.lang.String param0, java.lang.String param1)
      throws org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdUnusedException, org.sakaiproject.exception.TypeException,
          org.sakaiproject.exception.InUseException,
          org.sakaiproject.exception.ServerOverloadException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.removeProperty(param0, param1);
  }
  public static void moveIntoFolder(java.lang.String param0, java.lang.String param1)
      throws org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdUnusedException, org.sakaiproject.exception.TypeException,
          org.sakaiproject.exception.InUseException, org.sakaiproject.exception.OverQuotaException,
          org.sakaiproject.exception.IdUsedException,
          org.sakaiproject.exception.InconsistentException,
          org.sakaiproject.exception.ServerOverloadException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return;

    service.moveIntoFolder(param0, param1);
  }
  /**
   * @param collectionId
   * @param name
   * @return
   * @throws org.sakaiproject.exception.IdLengthException
   * @throws org.sakaiproject.exception.IdUnusedException
   * @throws org.sakaiproject.exception.TypeException
   */
  public static org.sakaiproject.content.api.ContentCollectionEdit addCollection(
      java.lang.String collectionId, java.lang.String name)
      throws org.sakaiproject.exception.IdUsedException,
          org.sakaiproject.exception.IdInvalidException,
          org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdUnusedException,
          org.sakaiproject.exception.IdLengthException, org.sakaiproject.exception.TypeException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.addCollection(collectionId, name);
  }
  public static java.lang.String merge(
      java.lang.String param0,
      org.w3c.dom.Element param1,
      java.lang.String param2,
      java.lang.String param3,
      java.util.Map param4,
      java.util.HashMap param5,
      java.util.Set param6) {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.merge(param0, param1, param2, param3, param4, param5, param6);
  }
Example #26
0
  /**
   * Parse and load selected XML data file
   *
   * @return String that is used to determine the place where control is to be sent in
   *     ControlImportProducer (reportNavigationCases method)
   * @throws SecurityException
   */
  public String process() throws SecurityException {
    ToolSession toolSession = sessionManager.getCurrentToolSession();
    List refs = null;
    String id = null;
    if (toolSession.getAttribute(FilePickerHelper.FILE_PICKER_CANCEL) == null
        && toolSession.getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) != null) {
      refs = (List) toolSession.getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
      if (refs == null || refs.size() != 1) {
        return "no-reference";
      }
      Reference ref = (Reference) refs.get(0);
      id = ref.getId();
    }
    try {
      contentHostingService.checkResource(id);
    } catch (PermissionException e) {
      return "permission-exception";
    } catch (IdUnusedException e) {
      return "idunused-exception";
    } catch (TypeException e) {
      return "type-exception";
    }
    try {
      evalImportLogic.load(id);
    } catch (Exception e) {
      return "exception";
    }

    toolSession.removeAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
    toolSession.removeAttribute(FilePickerHelper.FILE_PICKER_CANCEL);
    return "importing";
  }
  public void removeImageAttachToRank(final Rank rank, final RankImage imageAttach) {
    LOG.info("removeImageAttachToRank(final Rank rank, final RankImage imageAttach)");
    if (rank == null || imageAttach == null) {
      throw new IllegalArgumentException("Null Argument");
    }

    if (!isRanksEnabled()) {
      LOG.warn("removeImageAttachToRank invoked, but ranks are disabled");
      return;
    }

    HibernateCallback hcb =
        session -> {
          Rank returnedData = (Rank) session.get(RankImpl.class, rank.getId());
          RankImage returnedAttach =
              (RankImage) session.get(RankImageImpl.class, Long.valueOf(imageAttach.getId()));
          if (returnedData != null) {
            returnedData.setRankImage(null);
            session.saveOrUpdate(returnedData);

            if (returnedAttach.getAttachmentId().toLowerCase().startsWith("/attachment"))
              try {
                contentHostingService.removeResource(returnedAttach.getAttachmentId());
                session.delete(returnedAttach);
              } catch (PermissionException | IdUnusedException | TypeException | InUseException e) {
                e.printStackTrace();
              }
          }
          return null;
        };
    getHibernateTemplate().execute(hcb);
  }
  public static org.sakaiproject.content.api.ContentResource addAttachmentResource(
      java.lang.String param0,
      java.lang.String param1,
      byte[] param2,
      org.sakaiproject.entity.api.ResourceProperties param3)
      throws org.sakaiproject.exception.IdInvalidException,
          org.sakaiproject.exception.InconsistentException,
          org.sakaiproject.exception.IdUsedException,
          org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.OverQuotaException,
          org.sakaiproject.exception.ServerOverloadException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.addAttachmentResource(param0, param1, param2, param3);
  }
  public static org.sakaiproject.content.api.ContentResourceEdit addResource(
      java.lang.String collectionId,
      java.lang.String basename,
      java.lang.String extension,
      int maximum_tries)
      throws org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdUniquenessException,
          org.sakaiproject.exception.IdLengthException,
          org.sakaiproject.exception.IdInvalidException,
          org.sakaiproject.exception.IdUnusedException,
          org.sakaiproject.exception.OverQuotaException,
          org.sakaiproject.exception.ServerOverloadException {
    org.sakaiproject.content.api.ContentHostingService service = getInstance();
    if (service == null) return null;

    return service.addResource(collectionId, basename, extension, maximum_tries);
  }
 public InputStream getInputStream(PaperFile paperFile) {
   PaperFileImpl impl = castToImpl(paperFile);
   String path = impl.getPath();
   try {
     ContentResource resource = contentHostingService.getResource(path);
     return resource.streamContent();
   } catch (Exception e) {
     LOG.info("Failed to get stream for: " + path);
   }
   return null;
 }