use of org.apache.chemistry.opencmis.client.api.Document in project core-geonetwork by geonetwork.
the class CMISUtils method saveDocument.
public Document saveDocument(String key, CmisObject cmisObject, Map<String, Object> properties, InputStream is, final Date changeDate) throws IOException {
// Don't use caching for this process.
OperationContext oc = createOperationContext();
oc.setCacheEnabled(false);
// Split the filename and parent folder from the key.
int lastFolderDelimiterKeyIndex = key.lastIndexOf(cmisConfiguration.getFolderDelimiter());
String filenameKey = key.substring(lastFolderDelimiterKeyIndex + 1);
// Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
properties.put(PropertyIds.NAME, filenameKey);
if (changeDate != null) {
properties.put(PropertyIds.LAST_MODIFICATION_DATE, changeDate);
}
int isLength = is.available();
ContentStream contentStream = cmisConfiguration.getClient().getObjectFactory().createContentStream(key, isLength, Files.probeContentType(new File(key).toPath()), is);
// If we have a cmisObject then lets refresh it to make sure it still exists.
if (cmisObject != null) {
try {
cmisObject.refresh();
} catch (CmisObjectNotFoundException e) {
cmisObject = null;
}
}
Document doc;
if (cmisObject != null) {
try {
// If the document is found then we are updating the existing document.
doc = (Document) cmisObject;
// The CMIS default it to create minor versions on updates. If we are to create major versions on update then we need to update the document a little different.
if (cmisConfiguration.getVersioningState().equals(VersioningState.MAJOR) && cmisConfiguration.isVersioningMajorOnUpdate() && doc.isVersionable() && doc.isMajorVersion()) {
// If there is an existing checkout then cancel it.
if (doc.isVersionSeriesCheckedOut()) {
doc.cancelCheckOut();
}
ObjectId objectID = doc.checkOut();
CmisObject o = cmisConfiguration.getClient().getObject(objectID, oc);
((Document) o).checkIn(true, properties, contentStream, null);
} else {
doc.updateProperties(properties, true);
doc.setContentStream(contentStream, true, true);
}
if (cmisConfiguration.existSecondaryProperty()) {
// need to reload document to avoid "Document is not the latest version" when updating secondary types.
doc = (Document) cmisConfiguration.getClient().getObjectByPath(key, oc);
}
// Avoid CMIS API call is info is not enabled.
if (Logger.getLogger(Geonet.RESOURCES).isInfoEnabled()) {
Log.info(Geonet.RESOURCES, String.format("Updated resource '%s'. Current version '%s'.", key, doc.getVersionLabel()));
}
} catch (CmisConstraintException e) {
Log.warning(Geonet.RESOURCES, String.format("No allowed to modify existing resource '%s' due to constraint violation or lock.", key));
throw new NotAllowedException(String.format("No allowed to modify existing resource '%s' due to constraint violation or lock.", key));
} catch (CmisPermissionDeniedException e) {
Log.warning(Geonet.RESOURCES, String.format("No permissions to update resource '%s'.", key));
throw new NotAllowedException(String.format("No permissions to update resource '%s'.", key));
}
} else {
// If the document is not found then we are adding a new document.
// Get parent folder.
String parentKey = key.substring(0, lastFolderDelimiterKeyIndex);
try {
Folder parentFolder = getFolderCache(parentKey, true);
doc = parentFolder.createDocument(properties, contentStream, cmisConfiguration.getVersioningState());
// Avoid CMIS API call is info is not enabled.
if (Logger.getLogger(Geonet.RESOURCES).isInfoEnabled()) {
Log.info(Geonet.RESOURCES, String.format("Added resource '%s'.", doc.getPaths().get(0)));
}
} catch (CmisPermissionDeniedException ex) {
Log.warning(Geonet.RESOURCES, String.format("No permissions to add resource '%s'.", key));
throw new NotAllowedException(String.format("No permissions to add resource '%s'.", key));
} catch (ResourceNotFoundException e) {
throw new IOException("Error getting resource from cache: " + parentKey, e);
}
}
return doc;
}
use of org.apache.chemistry.opencmis.client.api.Document in project manifoldcf by apache.
the class CmisRepositoryConnector method processDocuments.
/**
* Process a set of documents.
* This is the method that should cause each document to be fetched, processed, and the results either added
* to the queue of documents for the current job, and/or entered into the incremental ingestion manager.
* The document specification allows this class to filter what is done based on the job.
* The connector will be connected before this method can be called.
*@param documentIdentifiers is the set of document identifiers to process.
*@param statuses are the currently-stored document versions for each document in the set of document identifiers
* passed in above.
*@param activities is the interface this method should use to queue up new document references
* and ingest documents.
*@param jobMode is an integer describing how the job is being run, whether continuous or once-only.
*@param usesDefaultAuthority will be true only if the authority in use for these documents is the default one.
*/
@Override
public void processDocuments(String[] documentIdentifiers, IExistingVersions statuses, Specification spec, IProcessActivity activities, int jobMode, boolean usesDefaultAuthority) throws ManifoldCFException, ServiceInterruption {
// Extract what we need from the spec
String cmisQuery = StringUtils.EMPTY;
for (int i = 0; i < spec.getChildCount(); i++) {
SpecificationNode sn = spec.getChild(i);
if (sn.getType().equals(JOB_STARTPOINT_NODE_TYPE)) {
cmisQuery = sn.getAttributeValue(CmisConfig.CMIS_QUERY_PARAM);
break;
}
}
for (String documentIdentifier : documentIdentifiers) {
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("CMIS: Processing document identifier '" + documentIdentifier + "'");
getSession();
// Load the object. If this fails, it has been deleted.
CmisObject cmisObject;
try {
cmisObject = session.getObject(documentIdentifier);
} catch (CmisObjectNotFoundException e) {
cmisObject = null;
}
if (cmisObject == null) {
activities.deleteDocument(documentIdentifier);
continue;
}
String versionString;
if (cmisObject.getBaseType().getId().equals(BaseTypeId.CMIS_DOCUMENT.value())) {
Document document = (Document) cmisObject;
// Since documents that are not current have different node id's, we can return a constant version,
// EXCEPT when the document is not the current one (in which case we delete)
boolean isCurrentVersion;
try {
Document d = document.getObjectOfLatestVersion(false);
isCurrentVersion = d.getId().equals(documentIdentifier);
} catch (CmisObjectNotFoundException e) {
isCurrentVersion = false;
}
if (isCurrentVersion) {
// System.out.println(" is latest version");
// versionString = documentIdentifier + ":" + cmisQuery;
// take into account of the last modification date
long lmdSeconds = document.getLastModificationDate().getTimeInMillis();
versionString = documentIdentifier + lmdSeconds + ":" + cmisQuery;
} else {
// System.out.println(" is NOT latest version");
activities.deleteDocument(documentIdentifier);
continue;
}
} else {
// a CMIS folder will always be processed
// System.out.println(" is folder");
versionString = StringUtils.EMPTY;
}
if (versionString.length() == 0 || activities.checkDocumentNeedsReindexing(documentIdentifier, versionString)) {
// Index this document
String errorCode = null;
String errorDesc = null;
Long fileLengthLong = null;
long startTime = System.currentTimeMillis();
try {
String baseTypeId = cmisObject.getBaseType().getId();
if (baseTypeId.equals(BaseTypeId.CMIS_FOLDER.value())) {
// adding all the children for a folder
Folder folder = (Folder) cmisObject;
ItemIterable<CmisObject> children = folder.getChildren();
for (CmisObject child : children) {
activities.addDocumentReference(child.getId(), documentIdentifier, RELATIONSHIP_CHILD);
}
} else if (baseTypeId.equals(BaseTypeId.CMIS_DOCUMENT.value())) {
// content ingestion
Document document = (Document) cmisObject;
Date createdDate = document.getCreationDate().getTime();
Date modifiedDate = document.getLastModificationDate().getTime();
long fileLength = document.getContentStreamLength();
String fileName = document.getContentStreamFileName();
String mimeType = document.getContentStreamMimeType();
// documentURI
String documentURI = getDocumentURI(cmisObject);
// Do any filtering (which will save us work)
if (!activities.checkURLIndexable(documentURI)) {
activities.noDocument(documentIdentifier, versionString);
errorCode = IProcessActivity.EXCLUDED_URL;
errorDesc = "Excluding due to URL ('" + documentURI + "')";
continue;
}
if (!activities.checkMimeTypeIndexable(mimeType)) {
activities.noDocument(documentIdentifier, versionString);
errorCode = IProcessActivity.EXCLUDED_MIMETYPE;
errorDesc = "Excluding due to mime type (" + mimeType + ")";
continue;
}
if (!activities.checkLengthIndexable(fileLength)) {
activities.noDocument(documentIdentifier, versionString);
errorCode = IProcessActivity.EXCLUDED_LENGTH;
errorDesc = "Excluding due to length (" + fileLength + ")";
continue;
}
if (!activities.checkDateIndexable(modifiedDate)) {
activities.noDocument(documentIdentifier, versionString);
errorCode = IProcessActivity.EXCLUDED_DATE;
errorDesc = "Excluding due to date (" + modifiedDate + ")";
continue;
}
RepositoryDocument rd = new RepositoryDocument();
rd.setFileName(fileName);
rd.setMimeType(mimeType);
rd.setCreatedDate(createdDate);
rd.setModifiedDate(modifiedDate);
InputStream is = null;
try {
if (fileLength > 0)
is = document.getContentStream().getStream();
else
is = null;
} catch (CmisObjectNotFoundException e) {
// Document gone
activities.deleteDocument(documentIdentifier);
continue;
}
try {
// binary
if (is != null) {
rd.setBinary(is, fileLength);
} else {
rd.setBinary(new NullInputStream(0), 0);
}
// modify the query in order to get the cmis:objectId field
String modifiedQuery = CmisRepositoryConnectorUtils.getCmisQueryWithObjectId(cmisQuery);
// filter the fields selected in the query
CmisRepositoryConnectorUtils.addValuesOfProperties(document, rd, modifiedQuery);
try {
activities.ingestDocumentWithException(documentIdentifier, versionString, documentURI, rd);
fileLengthLong = new Long(fileLength);
errorCode = "OK";
} catch (IOException e) {
errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT);
errorDesc = e.getMessage();
handleIOException(e, "reading file input stream");
}
} catch (Exception ecc) {
ecc.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT);
errorDesc = e.getMessage();
handleIOException(e, "closing file input stream");
}
}
} else {
// Unrecognized document type
activities.noDocument(documentIdentifier, versionString);
errorCode = "UNKNOWNTYPE";
errorDesc = "Document type is unrecognized: '" + baseTypeId + "'";
}
} catch (ManifoldCFException e) {
if (e.getErrorCode() == ManifoldCFException.INTERRUPTED)
errorCode = null;
throw e;
} finally {
if (errorCode != null)
activities.recordActivity(new Long(startTime), ACTIVITY_READ, fileLengthLong, documentIdentifier, errorCode, errorDesc, null);
}
}
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project manifoldcf by apache.
the class CmisOutputConnector method addOrReplaceDocumentWithException.
@Override
public int addOrReplaceDocumentWithException(String documentURI, VersionContext pipelineDescription, RepositoryDocument document, String authorityNameString, IOutputAddActivity activities) throws ManifoldCFException, ServiceInterruption, IOException {
getSession();
boolean isDropZoneFolder = isDropZoneFolder(cmisQuery);
long startTime = System.currentTimeMillis();
String resultDescription = StringUtils.EMPTY;
Folder leafParent = null;
String fileName = StringUtils.EMPTY;
InputStream inputStream = null;
ReplayableInputStream replayableInputStream = null;
ContentStream contentStream = null;
// properties
// (minimal set: name and object type id)
Map<String, Object> properties = new HashMap<String, Object>();
Long binaryLength = null;
String mimeType = StringUtils.EMPTY;
try {
if (isDropZoneFolder) {
// Creation of the new Repository Node
fileName = document.getFileName();
Date creationDate = document.getCreatedDate();
Date lastModificationDate = document.getModifiedDate();
String objectId = StringUtils.EMPTY;
mimeType = document.getMimeType();
binaryLength = document.getBinaryLength();
// check if the repository connector includes the content path
String primaryPath = StringUtils.EMPTY;
List<String> sourcePath = document.getSourcePath();
if (sourcePath != null && !sourcePath.isEmpty()) {
primaryPath = sourcePath.get(0);
}
// if the source is CMIS Repository Connector we override the objectId for synchronizing with removeDocument method
if (isSourceRepoCmisCompliant(document)) {
String[] cmisObjectIdArray = (String[]) document.getField(PropertyIds.OBJECT_ID);
if (cmisObjectIdArray != null && cmisObjectIdArray.length > 0) {
objectId = cmisObjectIdArray[0];
}
// Mapping all the CMIS properties ...
/*
Iterator<String> fields = document.getFields();
while (fields.hasNext()) {
String field = (String) fields.next();
if(!StringUtils.equals(field, "cm:lastThumbnailModification")
|| !StringUtils.equals(field, "cmis:secondaryObjectTypeIds")) {
String[] valuesArray = (String[]) document.getField(field);
properties.put(field,valuesArray);
}
}
*/
}
// Agnostic metadata
properties.put(PropertyIds.OBJECT_TYPE_ID, EnumBaseObjectTypeIds.CMIS_DOCUMENT.value());
properties.put(PropertyIds.NAME, fileName);
properties.put(PropertyIds.CREATION_DATE, creationDate);
properties.put(PropertyIds.LAST_MODIFICATION_DATE, lastModificationDate);
// check objectId
if (StringUtils.isNotEmpty(objectId)) {
ObjectId objId = new ObjectIdImpl(objectId);
properties.put(PropertyIds.OBJECT_ID, objId);
}
// Content Stream
inputStream = document.getBinaryStream();
replayableInputStream = new ReplayableInputStream(inputStream);
contentStream = new ContentStreamImpl(fileName, BigInteger.valueOf(binaryLength), mimeType, replayableInputStream);
// create a new content
leafParent = getOrCreateLeafParent(parentDropZoneFolder, creationDate, Boolean.valueOf(createTimestampTree), primaryPath);
leafParent.createDocument(properties, contentStream, versioningState);
resultDescription = DOCUMENT_STATUS_ACCEPTED_DESC;
return DOCUMENT_STATUS_ACCEPTED;
} else {
resultDescription = DOCUMENT_STATUS_REJECTED_DESC;
return DOCUMENT_STATUS_REJECTED;
}
} catch (CmisContentAlreadyExistsException | CmisNameConstraintViolationException e) {
// updating the existing content
if (leafParent != null) {
String documentFullPath = leafParent.getPath() + CmisOutputConnectorUtils.SLASH + fileName;
String newFileName = fileName + System.currentTimeMillis();
Document currentContent = (Document) session.getObjectByPath(documentFullPath);
currentContent.updateProperties(properties);
replayableInputStream.restart(true);
contentStream = new ContentStreamImpl(newFileName, BigInteger.valueOf(binaryLength), mimeType, replayableInputStream);
currentContent.setContentStream(contentStream, true);
Logging.connectors.warn("CMIS: Document already exists - Updating: " + documentFullPath);
}
resultDescription = DOCUMENT_STATUS_ACCEPTED_DESC;
return DOCUMENT_STATUS_ACCEPTED;
} catch (Exception e) {
resultDescription = DOCUMENT_STATUS_REJECTED_DESC;
throw new ManifoldCFException(e.getMessage(), e);
} finally {
if (inputStream != null) {
inputStream.close();
}
activities.recordActivity(startTime, ACTIVITY_INJECTION, document.getBinaryLength(), documentURI, resultDescription, resultDescription);
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project esup-ecandidat by EsupPortail.
the class TestWsController method testWs.
@SuppressWarnings("unchecked")
public void testWs() throws IOException {
logger.info("********** Début des Tests des Webservices **********");
final EntityManagerFactory emf = Persistence.createEntityManagerFactory("pun-jpa-siscol");
final EntityManager em = emf.createEntityManager();
final ResourceBundle bundle = ResourceBundle.getBundle("test-ws");
final String codOpi = bundle.getString("opi.codOpi");
try {
logger.info("********** Vérifications OPI **********");
final Candidature candOpi = candidatureRepository.findOne(Integer.valueOf(bundle.getString("opi.idCand")));
if (countOpiData(em, "IND_OPI", codOpi) > 0) {
throw new RuntimeException("Impossible de lancer les tests, nettoyez d'abord les OPI");
}
logger.info("********** Vérifications OPI terminée, lancement des tests **********");
/* Checkine */
logger.info("********** Vérifications Checkine **********");
final Boolean isInes = siScolService.checkStudentINES(bundle.getString("checkine.ine"), bundle.getString("checkine.key"));
if (!isInes) {
throw new RuntimeException("Checkines ne fonctionne pas");
} else {
logger.info("Ok - " + bundle.getString("checkine.ine") + bundle.getString("checkine.key"));
}
/* Données individu */
logger.info("********** Test Données individu **********");
final String codEtu = bundle.getString("ind.codEtu");
final WSIndividu ind = siScolService.getIndividu(codEtu, null, null);
checkString(bundle, String.valueOf(ind.getCodEtu()), "ind.codEtu");
checkString(bundle, String.valueOf(ind.getCodInd()), "ind.codInd");
checkString(bundle, ind.getCodNneInd(), "ind.codNneInd");
checkString(bundle, ind.getCodCleNneInd(), "ind.codCleNneInd");
checkString(bundle, ind.getCodPayNai(), "ind.codPayNai");
checkString(bundle, ind.getCodDepNai(), "ind.codDepNai");
checkString(bundle, ind.getCodPayNat(), "ind.codPayNat");
checkString(bundle, ind.getLibNomPatInd(), "ind.libNomPatInd");
checkString(bundle, ind.getLibNomUsuInd(), "ind.libNomUsuInd");
checkString(bundle, ind.getLibPr1Ind(), "ind.libPr1Ind");
checkString(bundle, ind.getLibPr2Ind(), "ind.libPr2Ind");
checkString(bundle, ind.getLibVilNaiEtu(), "ind.libVilNaiEtu");
/* Données bac */
logger.info("********** Test Données bac **********");
final WSBac bac = ind.getBac();
checkString(bundle, bac.getCodBac(), "bac.codBac");
checkString(bundle, bac.getCodDep(), "bac.codDep");
checkString(bundle, bac.getCodEtb(), "bac.codEtb");
checkString(bundle, bac.getCodMnb(), "bac.codMnb");
checkString(bundle, bac.getDaaObtBacIba(), "bac.daaObtBacIba");
checkString(bundle, bac.getTemInsAdm(), "bac.temInsAdm");
checkString(bundle, bac.getCodSpeBacPre(), "bac.codSpeBacPre");
checkString(bundle, bac.getCodSpe1Bac(), "bac.codSpe1Bac");
checkString(bundle, bac.getCodSpe2Bac(), "bac.codSpe2Bac");
checkString(bundle, bac.getCodOpt1Bac(), "bac.codOpt1Bac");
checkString(bundle, bac.getCodOpt2Bac(), "bac.codOpt2Bac");
checkString(bundle, bac.getCodOpt3Bac(), "bac.codOpt3Bac");
checkString(bundle, bac.getCodOpt4Bac(), "bac.codOpt4Bac");
/* Données Adresse */
logger.info("********** Test Données adresse **********");
final WSAdresse adr = ind.getAdresse();
checkString(bundle, adr.getCodBdi(), "adr.codBdi");
checkString(bundle, adr.getCodCom(), "adr.codCom");
checkString(bundle, adr.getCodPay(), "adr.codPay");
checkString(bundle, adr.getLibAd1(), "adr.libAd1");
checkString(bundle, adr.getLibAd2(), "adr.libAd2");
checkString(bundle, adr.getLibAd3(), "adr.libAd3");
checkString(bundle, adr.getLibAde(), "adr.libAde");
checkString(bundle, adr.getNumTel(), "adr.numTel");
checkString(bundle, adr.getNumTelPort(), "adr.numTelPort");
/* Données Cursus (test de la taille de liste et de la premiere inscription) */
logger.info("********** Test Données Cursus interne **********");
final List<WSCursusInterne> listCursus = ind.getListCursusInterne();
checkString(bundle, String.valueOf(listCursus.size()), "cursus.size");
final WSCursusInterne cursus = listCursus.get(0);
checkString(bundle, cursus.getCodVet(), "cursus.codVet");
checkString(bundle, cursus.getLibVet(), "cursus.libVet");
checkString(bundle, cursus.getCodAnu(), "cursus.codAnu");
checkString(bundle, cursus.getCodMen(), "cursus.codMen");
checkString(bundle, cursus.getCodTre(), "cursus.codTre");
checkString(bundle, cursus.getNotVet(), "cursus.notVet");
checkString(bundle, String.valueOf(cursus.getBarNotVet()), "cursus.barNotVet");
/* Données PJ */
logger.info("********** Test Données PJ **********");
final WSPjInfo pjInfo = siScolService.getPjInfoFromApogee(bundle.getString("pj.codAnu"), bundle.getString("pj.codEtu"), bundle.getString("pj.codTpj"));
checkString(bundle, pjInfo.getCodAnu(), "pj.codAnu");
checkString(bundle, pjInfo.getCodTpj(), "pj.codTpj");
checkString(bundle, pjInfo.getLibTpj(), "pj.libTpj");
checkString(bundle, pjInfo.getNomFic(), "pj.nomFic");
checkString(bundle, String.valueOf(pjInfo.getTemDemPJ()), "pj.temDemPJ");
checkString(bundle, pjInfo.getStuPj(), "pj.stuPj");
checkString(bundle, pjInfo.getMtfRefus(), "pj.mtfRefus");
checkString(bundle, pjInfo.getCmtMtfRefus(), "pj.cmtMtfRefus");
checkString(bundle, pjInfo.getDatDemPj(), "pj.datDemPj");
checkString(bundle, pjInfo.getDatRecPj(), "pj.datRecPj");
checkString(bundle, pjInfo.getDatRefus(), "pj.datRefus");
checkString(bundle, pjInfo.getDatVal(), "pj.datVal");
checkString(bundle, pjInfo.getDatExp(), "pj.datExp");
checkString(bundle, pjInfo.getDaaPreTra(), "pj.daaPreTra");
/* Données PJ */
logger.info("********** Test Fichier PJ **********");
final InputStream pjFichier = siScolService.getPjFichierFromApogee(bundle.getString("pj.codAnu"), bundle.getString("pj.codEtu"), bundle.getString("pj.codTpj"));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final byte[] bytes = new byte[1024];
int count;
while ((count = pjFichier.read(bytes)) > 0) {
out.write(bytes, 0, count);
}
checkString(bundle, String.valueOf(out.size()), "filepj.size");
logger.info("********** Test OPI **********");
final Opi opi = opiRepository.findOne(candOpi.getIdCand());
opi.setDatPassageOpi(null);
opi.setCodOpi(null);
opiRepository.save(opi);
final PjOpiPK pk = new PjOpiPK(bundle.getString("opi.codOpi"), bundle.getString("opi.codTpj"));
final PjOpi pj = pjOpiRepository.findOne(pk);
pj.setDatDeversement(null);
pjOpiRepository.save(pj);
siScolService.creerOpiViaWS(candOpi.getCandidat(), true);
logger.info("********** Vérification OPI **********");
checkOpiData(em, "IND_OPI", codOpi);
checkOpiData(em, "OPI_BAC", codOpi);
checkOpiData(em, "VOEUX_INS", codOpi);
checkOpiData(em, "ADRESSE_OPI", codOpi);
checkOpiData(em, "OPI_PJ", codOpi);
logger.info("********** Vérification OPI PJ **********");
final String requete = "Select a from IndOpi a where a.codOpiIntEpo='" + codOpi + "'";
final Query query = em.createQuery(requete, IndOpi.class);
final List<IndOpi> lindopi = query.getResultList();
final IndOpi indOpi = lindopi.get(0);
final Session cmisSession = getCmisSession(bundle);
final Folder folder = (Folder) cmisSession.getObject(cmisSession.createObjectId(bundle.getString("opi.pj.candidatureId")));
final String pathDoc = folder.getPath() + "/" + indOpi.getCodIndOpi() + "_OPI/PJ_" + bundle.getString("pj.codTpj") + "_" + indOpi.getCodIndOpi() + bundle.getString("opi.pj.ext");
logger.info("Recherche par path : " + pathDoc);
final Document d = (Document) cmisSession.getObjectByPath(pathDoc);
checkString(bundle, String.valueOf(d.getContentStreamLength()), "opi.pj.size");
logger.info("********** Fin des Tests des Webservices **********");
} catch (final Exception e) {
e.printStackTrace();
} finally {
em.close();
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project esup-ecandidat by EsupPortail.
the class FileManagerCmisImpl method createFileFromUpload.
/**
* @see fr.univlorraine.ecandidat.services.file.FileManager#createFileFromUpload(fr.univlorraine.ecandidat.utils.ByteArrayInOutStream, java.lang.String,
* java.lang.String, long, java.lang.String,
* java.lang.String, fr.univlorraine.ecandidat.entities.ecandidat.Candidature, java.lang.Boolean)
*/
@Override
public FileCustom createFileFromUpload(final ByteArrayInOutStream file, final String mimeType, final String filename, final long length, final String typeFichier, final String prefixe, final Candidature candidature, final Boolean commune) throws FileException {
ByteArrayInputStream bis = null;
try {
final String name = prefixe + "_" + filename;
final Map<String, Object> properties = new HashMap<>();
properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
properties.put(PropertyIds.NAME, name);
bis = file.getInputStream();
final ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(length), mimeType, bis);
Folder master;
if (typeFichier.equals(ConstanteUtils.TYPE_FICHIER_GESTIONNAIRE)) {
master = getFolderGestionnaire();
} else {
master = getFolderCandidature(candidature, commune);
}
// versioning
VersioningState versioningState = VersioningState.NONE;
if (enableVersioningCmis != null && enableVersioningCmis) {
versioningState = VersioningState.MINOR;
}
final Document d = master.createDocument(properties, contentStream, versioningState);
return getFileFromDoc(d, filename, prefixe);
} catch (final Exception e) {
// Suppression de l'erreur org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: Bad Gateway
if (!MethodUtils.checkExceptionAndMessage(e, CmisRuntimeException.class, ConstanteUtils.CMIS_ERROR_BAD_GATEWAY)) {
logger.error("Stockage de fichier - CMIS : erreur de creation du fichier ", e);
}
throw new FileException(applicationContext.getMessage("file.error.create", null, UI.getCurrent().getLocale()), e);
} finally {
MethodUtils.closeRessource(bis);
MethodUtils.closeRessource(file);
}
}
Aggregations