示例#1
0
 /**
  * {@inheritDoc}
  *
  * @see org.prowim.dms.alfresco.ContentService#deleteContent(java.lang.String)
  */
 @Interceptors(AuthenticationInterceptor.class)
 public void deleteContent(String uuid) throws DMSException {
   Validate.notNull(uuid);
   this.getContentService();
   final Reference reference = new Reference(DMSStoreRegistry.STORE_REF, uuid, null);
   final Predicate predicate = new Predicate(new Reference[] {reference}, null, null);
   final CMLDelete delete = new CMLDelete(predicate);
   final CML cml = new CML();
   cml.setDelete(new CMLDelete[] {delete});
   try {
     WebServiceFactory.getRepositoryService().update(cml);
   } catch (RepositoryFault e) {
     String message = "Could not delete content: ";
     LOG.error(message, e);
     DMSFault 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 dmsFault = new DMSFault();
     dmsFault.setMessage(message);
     throw new DMSException(message, dmsFault, e.getCause());
   }
 }
示例#2
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());
    }
  }
示例#3
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.prowim.dms.alfresco.ContentService#updateDMSDocument(org.prowim.datamodel.dms.Document,
   *     java.lang.String)
   */
  @Override
  @Interceptors(AuthenticationInterceptor.class)
  public void updateDMSDocument(Document document, String uuid) throws DMSException {
    Validate.notNull(document);
    Validate.notNull(uuid);

    ContentFormat contentFormat =
        new ContentFormat(document.getContentType(), DMSConstants.ENCODING);
    try {
      DocumentIdentification documentIdentification = new DocumentIdentification(uuid, null);
      getContentService()
          .write(
              this.getReference(
                  documentIdentification.getPath(),
                  documentIdentification.getUuid(),
                  DMSStoreRegistry.STORE_REF),
              Constants.PROP_CONTENT,
              document.getContent(),
              contentFormat);

    } catch (ContentFault e) {
      String message = "Could not update content: ";
      LOG.error(message, e);
      DMSFault 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 dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e.getCause());
    }
  }
示例#4
0
  /**
   * {@inheritDoc}
   *
   * @see org.prowim.dms.alfresco.ContentService#updateContent(byte[], java.lang.String,
   *     java.lang.String, java.lang.String, java.lang.String, boolean)
   */
  @Interceptors(AuthenticationInterceptor.class)
  public VersionResult updateContent(
      byte[] content,
      String name,
      String mimeType,
      String frameID,
      String username,
      boolean createNewVersion)
      throws OntologyErrorException, DMSException {
    Validate.notNull(content);
    Validate.notNull(name);
    Validate.notNull(mimeType);
    Validate.notNull(frameID);
    ContentFormat contentFormat = new ContentFormat(mimeType, DMSConstants.ENCODING);
    try {
      DocumentIdentification documentIdentification =
          documentManagement.getDocumentIdentification(frameID);
      Content contentRef =
          getContentService()
              .write(
                  this.getReference(
                      documentIdentification.getPath(),
                      documentIdentification.getUuid(),
                      DMSStoreRegistry.STORE_REF),
                  Constants.PROP_CONTENT,
                  content,
                  contentFormat);

      if (createNewVersion) {
        return createNewVersion(name, username, contentRef.getNode().getUuid());
      }

      /** Set the document identification. */
      documentManagement.setDocumentIdentification(contentRef.getNode().getUuid(), null, frameID);
      if (this.commonBean.getDirectClassOfInstance(frameID).equals(Relation.Classes.KNOWLEDGE_LINK))
        documentManagement.bindDocument(
            contentRef.getNode().getUuid(),
            name,
            frameID,
            getLastVersionLabel(contentRef.getNode()));
      return null;
    } catch (ContentFault e) {
      String message = "Could not update content: ";
      LOG.error(message, e);
      DMSFault 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 dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e.getCause());
    }
  }
示例#5
0
 /**
  * {@inheritDoc}
  *
  * @see org.prowim.dms.alfresco.ContentService#getAllDocuments()
  */
 @Override
 @Interceptors(AuthenticationInterceptor.class)
 public DocumentContentPropertiesArray getAllDocuments() throws DMSException {
   SearchService searcher = new SearchService();
   try {
     return searcher.getAllDocuments(DMSConstants.getCustomerFolderID());
   } catch (RemoteException e) {
     String message = "An remote exception occurs while searching the DMS";
     LOG.error(message, e);
     DMSFault dmsFault = new DMSFault();
     dmsFault.setMessage(message);
     throw new DMSException(message, dmsFault, e);
   }
 }
示例#6
0
 /**
  * {@inheritDoc}
  *
  * @see org.prowim.dms.alfresco.ContentService#deleteDocument(java.lang.String)
  */
 @Interceptors(AuthenticationInterceptor.class)
 public void deleteDocument(String frameID) throws OntologyErrorException, DMSException {
   Validate.notNull(frameID);
   DocumentIdentification documentIdentification =
       documentManagement.getDocumentIdentification(frameID);
   documentManagement.clearDocumentIdentificationForPI(frameID);
   String uuid = documentIdentification.getUuid();
   if (uuid != null && !uuid.equals(ProcessEngineConstants.Variables.Common.NULL_VALUE)) {
     this.deleteContent(uuid);
   } else {
     String message = "The ID of the document in the ontology is NULL ";
     DMSFault dmsFault = new DMSFault();
     dmsFault.setMessage(message);
     throw new DMSException(message, dmsFault);
   }
 }
示例#7
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());
    }
  }
示例#8
0
  /**
   * {@inheritDoc}
   *
   * @see org.prowim.dms.alfresco.ContentService#downloadDocumentInVersionFromID(java.lang.String,
   *     java.lang.String)
   */
  @Override
  @Interceptors(AuthenticationInterceptor.class)
  public Document downloadDocumentInVersionFromID(String id, String versionLabel)
      throws DMSException {
    Document result = null;

    String message = "Could not download document from DMS :  id ";
    try {
      result = getDocumentInVersion(id, versionLabel);
    } catch (RemoteException e) {
      LOG.error(message + id, e);
      DMSFault dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e);
    }
    if (result != null) return result;
    else throw new IllegalStateException(message + id);
  }
示例#9
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;
  }
示例#10
0
  /**
   * {@inheritDoc}
   *
   * @see org.prowim.dms.alfresco.ContentService#updateDocument(org.prowim.datamodel.dms.Document,
   *     java.lang.String)
   */
  @Override
  @Interceptors(AuthenticationInterceptor.class)
  public void updateDocument(Document document, String userName) throws DMSException {
    Validate.notNull(document);
    Validate.notNull(userName);

    ContentFormat contentFormat =
        new ContentFormat(document.getContentType(), DMSConstants.ENCODING);
    try {
      String uuid = findFolderOrContent(document.getName());
      DocumentIdentification documentIdentification = new DocumentIdentification(uuid, null);
      Content contentRef =
          getContentService()
              .write(
                  this.getReference(
                      documentIdentification.getPath(),
                      documentIdentification.getUuid(),
                      DMSStoreRegistry.STORE_REF),
                  Constants.PROP_CONTENT,
                  document.getContent(),
                  contentFormat);

      createNewVersion(document.getName(), userName, contentRef.getNode().getUuid());
    } catch (ContentFault e) {
      String message = "Could not update content: ";
      LOG.error(message, e);
      DMSFault 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 dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e.getCause());
    } catch (OntologyErrorException e) {
      // TODO $Author: khodaei $ Auto-generated catch block
      LOG.error("Your log-message: ", e);
    }
  }
示例#11
0
  /**
   * {@inheritDoc}
   *
   * @see org.prowim.dms.alfresco.ContentService#downloadDocument(java.lang.String)
   */
  @Interceptors(AuthenticationInterceptor.class)
  public Document downloadDocument(String frameID) throws OntologyErrorException, DMSException {
    Validate.notNull(frameID, "frame: " + frameID);
    Document document = null;
    DocumentIdentification documentIdentification =
        documentManagement.getDocumentIdentification(frameID);
    String uuid = documentIdentification.getUuid();
    Reference contentReference = new Reference(DMSStoreRegistry.STORE_REF, uuid, null);

    try {
      Content[] readResult =
          this.getContentService()
              .read(
                  new Predicate(
                      new Reference[] {contentReference}, DMSStoreRegistry.STORE_REF, null),
                  Constants.PROP_CONTENT);
      /** fetch the content. */
      Content content = readResult[0];
      document = getContent(content.getNode(), DMSStoreRegistry.STORE_REF);

    } catch (ContentFault e) {
      String message = "could not get dms content: ";
      LOG.error(message, e);
      DMSFault dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e);
    } catch (RemoteException e) {
      String message = "RemoteException: ";
      LOG.error(message, e);
      DMSFault dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException("Remote Excpetion : ", dmsFault, e);
    }
    if (document == null)
      throw new IllegalStateException("Cannot get the documents content: " + frameID);
    return document;
  }