/** * {@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()); } }
/** * {@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); } }
/** * {@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()); } }
/** * Gets the uuid to a document stored for the frame with id ) frameID. * * @param frameID the not null ID of the frame. * @return the uuid, if the frame has a document stored in DMS otherwise null. * @throws OntologyErrorException if an error occurs in ontology back end */ private String getUUID(String frameID) throws OntologyErrorException { Validate.notNull(frameID); DocumentIdentification documentIdentification = documentManagement.getDocumentIdentification(frameID); if (documentIdentification != null) { return documentIdentification.getUuid(); } else { return null; } }
/** * {@inheritDoc} * * @see * org.prowim.dms.alfresco.ContentService#getDocumentVersionHistoryFromProcessID(java.lang.String) */ @Override @Interceptors(AuthenticationInterceptor.class) public org.prowim.datamodel.dms.VersionHistory getDocumentVersionHistoryFromProcessID( String processID) throws OntologyErrorException, DMSException { // get the alfresco node id String processInformationID = processHelper.getChartProcessInformationID(processID); if (processInformationID == null) { throw new IllegalStateException( "Could not find process information for process with ID: " + processID); } DocumentIdentification documentIdentification = documentManagement.getDocumentIdentification(processInformationID); String uuid = documentIdentification.getUuid(); // return the version history return getDocumentVersionHistory(uuid); }
/** * {@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; }