示例#1
0
  /**
   * {@inheritDoc}
   *
   * @throws DMSException
   * @throws OntologyErrorException
   * @see org.prowim.dms.alfresco.ContentService#uploadDocument(org.prowim.datamodel.dms.Document,
   *     String)
   */
  @Override
  @Interceptors(AuthenticationInterceptor.class)
  public boolean uploadDocument(Document document, String userName)
      throws DMSException, OntologyErrorException {
    Validate.notNull(document);

    ContentServiceSoapBindingStub contentService = getContentService();
    ContentFormat contentFormat =
        new ContentFormat(document.getContentType(), DMSConstants.ENCODING);
    DMSFault dmsFault;

    try {
      if (findFolderOrContent(document.getName()) == null) {
        Reference contentReference =
            this.createReference(document.getName(), organizationEntity.getUser(userName).getID());

        contentService.write(
            contentReference, Constants.PROP_CONTENT, document.getContent(), contentFormat);
        makeVersionable(contentReference);
        return true;
      } else return false;
    } catch (ContentFault e) {
      String message = "Could not create content: ";
      LOG.error(message, e);
      dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e.getCause());
    } catch (RemoteException e) {
      String message = "Could not create connection: ";
      LOG.error(message, e);
      dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e.getCause());
    }
  }
示例#2
0
  /**
   * {@inheritDoc}
   *
   * @see org.prowim.dms.alfresco.ContentService#writeContent(byte[], java.lang.String,
   *     java.lang.String, java.lang.String, java.lang.String)
   */
  @Interceptors(AuthenticationInterceptor.class)
  public boolean writeContent(
      byte[] content, String name, String mimeType, String frameID, String username)
      throws OntologyErrorException, DMSException {
    Validate.notNull(content);
    Validate.notEmpty(name);
    Validate.notNull(mimeType);
    Validate.notNull(frameID);

    ContentServiceSoapBindingStub contentService = getContentService();
    ContentFormat contentFormat = new ContentFormat(mimeType, DMSConstants.ENCODING);
    DMSFault dmsFault;
    try {
      if (findFolderOrContent(name) == null) {
        Reference contentReference =
            this.createReference(name, organizationEntity.getUser(username).getID());

        Content contentRef =
            contentService.write(contentReference, Constants.PROP_CONTENT, content, contentFormat);
        makeVersionable(contentReference);
        documentManagement.setDocumentIdentification(contentRef.getNode().getUuid(), name, frameID);
        if (this.commonBean
            .getDirectClassOfInstance(frameID)
            .equals(Relation.Classes.KNOWLEDGE_LINK))
          documentManagement.bindDocument(
              contentRef.getNode().getUuid(),
              name,
              frameID,
              getLastVersionLabel(contentRef.getNode()));
        return true;
      } else return false;
    } catch (ContentFault e) {
      String message = "Could not create content: ";
      LOG.error(message, e);
      dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e.getCause());
    } catch (RemoteException e) {
      String message = "Could not create connection: ";
      LOG.error(message, e);
      dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e.getCause());
    }
  }
示例#3
0
  /**
   * Gets the content from Alfresco DMS.
   *
   * @param reference not null {@link Reference}
   * @param store the store.
   * @return not null {@link Document}
   * @throws RemoteException If the {@link Reference} is not equivalent to an existing {@link Node}.
   * @throws DMSException if an error occurs in DMS back end
   */
  private Document getContent(Reference reference, Store store)
      throws RemoteException, DMSException {
    Validate.notNull(reference);
    Validate.notNull(store);

    /** Get the content service. */
    final ContentServiceSoapBindingStub contentService = this.getContentService();
    Document result = null;

    /** Read the content from the respository. */
    Content[] readResult;
    readResult =
        contentService.read(
            new Predicate(new Reference[] {reference}, store, null), Constants.PROP_CONTENT);
    Content content = readResult[0];

    if (readResult != null && content != null && content.getUrl() != null) {
      final String fileName = this.getName(content.getUrl());
      File tempFile = new File(ResourcesLocator.getResourcesTempDir() + fileName);

      /** Get the content from the download servlet using the URL and display it. */
      /** Copy content in a temporary direcoty. */
      ContentUtils.copyContentToFile(content, tempFile);

      try {
        FileInputStream fin;
        fin = new FileInputStream(tempFile);
        int bytesCount = (int) tempFile.length();
        byte[] contentBytes = new byte[bytesCount];
        fin.read(contentBytes);
        result = new Document(fileName, content.getFormat().getMimetype(), contentBytes);
        fin.close();
        this.deleteTempFile(tempFile);
      } catch (IOException e) {
        String message = "IO Error: ";
        LOG.error(message, e);
        DMSFault dmsFault = new DMSFault();
        dmsFault.setMessage(message);
        throw new DMSException(message, dmsFault, e);
      }
    }

    return result;
  }