org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException Java Examples
The following examples show how to use
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Converter.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * Converts a list of calendar objects * * @param calendar the list of gregorian calendars * * @return list of XML gregorian calendars */ public static List<XMLGregorianCalendar> convertCalendar(List<GregorianCalendar> calendar) { if (calendar == null) { return null; } DatatypeFactory df; try { df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new CmisRuntimeException("Convert exception: " + e.getMessage(), e); } List<XMLGregorianCalendar> result = new ArrayList<XMLGregorianCalendar>(); for (GregorianCalendar cal : calendar) { result.add(df.newXMLGregorianCalendar(cal)); } return result; }
Example #2
Source File: CMISUtils.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public static <T> T copy(T source) { T target = null; try ( CopyOutputStream cos = new CopyOutputStream(); ObjectOutputStream out = new ObjectOutputStream(cos) ) { out.writeObject(source); out.flush(); try (ObjectInputStream in = new ObjectInputStream(cos.getInputStream())) { target = (T) in.readObject(); } } catch (Exception e) { throw new CmisRuntimeException("Object copy failed!", e); } return target; }
Example #3
Source File: ConformanceCmisServiceWrapper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Converts the given exception into a CMIS exception. */ protected CmisBaseException createCmisException(Exception e) { if (e == null) { // should never happen // if it happens its the fault of the framework... return new CmisRuntimeException("Unknown exception!"); } else if (e instanceof CmisBaseException) { return (CmisBaseException) e; } else { // should not happen if the connector works correctly // it's alarming enough to log the exception LOG.warn(e.toString(), e); return new CmisRuntimeException(e.getMessage(), e); } }
Example #4
Source File: AlfrescoCmisServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public String createPolicy( String repositoryId, Properties properties, String folderId, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) { checkRepositoryId(repositoryId); // get the parent folder getOrCreateFolderInfo(folderId, "Parent Folder"); String objectTypeId = connector.getObjectTypeIdProperty(properties); connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_POLICY); // we should never get here - policies are not creatable! throw new CmisRuntimeException("Polcies cannot be created!"); }
Example #5
Source File: Converter.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * Converts a calendar object * * @param calendar gregorian calendar * * @return an XML gregorian calendar */ public static XMLGregorianCalendar convertCalendar(GregorianCalendar calendar) { if (calendar == null) { return null; } DatatypeFactory df; try { df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new CmisRuntimeException("Convert exception: " + e.getMessage(), e); } return df.newXMLGregorianCalendar(calendar); }
Example #6
Source File: RepositoryConnectorFactory.java From iaf with Apache License 2.0 | 5 votes |
protected FilterCmisService createService(CallContext context) { HttpSessionCmisService service = null; try { service = new HttpSessionCmisService(context); LOG.info("Created proxy repository service"); } catch (Exception e) { throw new CmisRuntimeException("Could not create service instance: " + e, e); } return service; }
Example #7
Source File: CmisServiceImpl.java From document-management-system with GNU General Public License v2.0 | 5 votes |
@Override public List<RepositoryInfo> getRepositoryInfos(ExtensionsData extension) { log.debug("getRepositoryInfos({})", extension); try { List<RepositoryInfo> infos = new ArrayList<RepositoryInfo>(); infos.add(getRepository().getRepositoryInfo(getCallContext())); return infos; } catch (Exception e) { throw new CmisRuntimeException(e.getMessage(), e); } }
Example #8
Source File: CMISMapping.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the CMIS Type Id given the Alfresco QName for the type in any * Alfresco model * * @param scope BaseTypeId * @param typeQName QName * @return String */ public String getCmisTypeId(BaseTypeId scope, QName typeQName) { String typeId = mapAlfrescoQNameToTypeId.get(typeQName); if (typeId == null) { String p = null; switch (scope) { case CMIS_DOCUMENT: p = "D"; break; case CMIS_FOLDER: p = "F"; break; case CMIS_RELATIONSHIP: p = "R"; break; case CMIS_SECONDARY: p = "P"; break; case CMIS_POLICY: p = "P"; break; case CMIS_ITEM: p = "I"; break; default: throw new CmisRuntimeException("Invalid base type!"); } return p + ":" + typeQName.toPrefixString(namespaceService); } else { return typeId; } }
Example #9
Source File: CMISTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * ALF-20389 Test Alfresco cmis stream interceptor that checks content stream for mimetype. Only ContentStreamImpl extensions should take palace. */ @Test public void testGetRepositoryInfos() { boolean cmisEx = false; List<RepositoryInfo> infoDataList = null; try { infoDataList = withCmisService(new CmisServiceCallback<List<RepositoryInfo>>() { @Override public List<RepositoryInfo> execute(CmisService cmisService) { ExtensionDataImpl result = new ExtensionDataImpl(); List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>(); result.setExtensions(extensions); return cmisService.getRepositoryInfos(result); } }); } catch (CmisRuntimeException e) { cmisEx = true; } assertNotNull(cmisEx ? "CmisRuntimeException was thrown. Please, take a look on ALF-20389" : "No CMIS repository information was retrieved", infoDataList); }
Example #10
Source File: ConformanceCmisServiceWrapper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private BigInteger convertToBigInteger(Object obj) { try { if (obj instanceof BigInteger) { return (BigInteger) obj; } else if (obj instanceof String) { return new BigInteger((String) obj); } else if (obj instanceof Number) { return BigInteger.valueOf(((Number) obj).longValue()); } } catch (NumberFormatException e) { throw new CmisRuntimeException("Invalid number: " + obj.toString(), e); } return null; }
Example #11
Source File: AlfrescoCmisServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ObjectData getFolderParent(String repositoryId, String folderId, String filter, ExtensionsData extension) { checkRepositoryId(repositoryId); // get the node ref CMISNodeInfo info = getOrCreateFolderInfo(folderId, "Folder"); // the root folder has no parent if (info.isRootFolder()) { throw new CmisInvalidArgumentException("Root folder has no parent!"); } // get the parent List<CMISNodeInfo> parentInfos = info.getParents(); if (parentInfos.isEmpty()) { throw new CmisRuntimeException("Folder has no parent and is not the root folder?!"); } CMISNodeInfo parentInfo = addNodeInfo(parentInfos.get(0)); ObjectData result = connector.createCMISObject( parentInfo, filter, false, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false); boolean isObjectInfoRequired = getContext().isObjectInfoRequired(); if (isObjectInfoRequired) { getObjectInfo( repositoryId, parentInfo.getObjectId(), IncludeRelationships.NONE); } return result; }
Example #12
Source File: CMISConnector.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns the root folder node ref. */ public NodeRef getRootNodeRef() { NodeRef rootNodeRef = (NodeRef)singletonCache.get(KEY_CMIS_ROOT_NODEREF); if (rootNodeRef == null) { rootNodeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() { public NodeRef doWork() throws Exception { return transactionService.getRetryingTransactionHelper().doInTransaction( new RetryingTransactionCallback<NodeRef>() { public NodeRef execute() throws Exception { NodeRef root = nodeService.getRootNode(storeRef); List<NodeRef> rootNodes = searchService.selectNodes(root, rootPath, null, namespaceService, false); if (rootNodes.size() != 1) { throw new CmisRuntimeException("Unable to locate CMIS root path " + rootPath); } return rootNodes.get(0); }; }, true); } }, AuthenticationUtil.getSystemUserName()); if (rootNodeRef == null) { throw new CmisObjectNotFoundException("Root folder path '" + rootPath + "' not found!"); } singletonCache.put(KEY_CMIS_ROOT_NODEREF, rootNodeRef); } return rootNodeRef; }
Example #13
Source File: AlfrescoCmisServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public String create( String repositoryId, Properties properties, String folderId, ContentStream contentStream, VersioningState versioningState, List<String> policies, ExtensionsData extension) { checkRepositoryId(repositoryId); // check properties if (properties == null || properties.getProperties() == null) { throw new CmisInvalidArgumentException("Properties must be set!"); } // get the type String objectTypeId = connector.getObjectTypeIdProperty(properties); // find the type TypeDefinitionWrapper type = connector.getOpenCMISDictionaryService().findType(objectTypeId); if (type == null) { throw new CmisInvalidArgumentException("Type '" + objectTypeId + "' is unknown!"); } // create object String newId = null; switch (type.getBaseTypeId()) { case CMIS_DOCUMENT: versioningState = getDocumentDefaultVersioningState(versioningState, type); newId = createDocument(repositoryId, properties, folderId, contentStream, versioningState, policies, null, null, extension); break; case CMIS_FOLDER: newId = createFolder(repositoryId, properties, folderId, policies, null, null, extension); break; case CMIS_POLICY: newId = createPolicy(repositoryId, properties, folderId, policies, null, null, extension); break; case CMIS_ITEM: newId = createItem(repositoryId, properties, folderId, policies, null, null, extension); break; default: break; } // check new object id if (newId == null) { throw new CmisRuntimeException("Creation failed!"); } boolean isObjectInfoRequired = getContext().isObjectInfoRequired(); if (isObjectInfoRequired) { try { getObjectInfo(repositoryId, newId, "*", IncludeRelationships.NONE); } catch (InvalidNodeRefException e) { throw new CmisRuntimeException("Creation failed! New object not found!"); } } // return the new object id return newId; }
Example #14
Source File: CMISConnector.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) { throw new CmisRuntimeException("Audit entry " + entryId + ": " + errorMsg, error); }
Example #15
Source File: CMISConnector.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Gets the content from the repository. */ public ContentStream getContentStream(CMISNodeInfo info, String streamId, BigInteger offset, BigInteger length) { // get the type and check if the object can have content TypeDefinitionWrapper type = info.getType(); checkDocumentTypeForContent(type); // looks like a document, now get the content ContentStreamImpl result = new ContentStreamImpl(); result.setFileName(info.getName()); // if streamId is set, fetch other content NodeRef streamNodeRef = info.getNodeRef(); if ((streamId != null) && (streamId.length() > 0)) { CMISNodeInfo streamInfo = createNodeInfo(streamId); if (!streamInfo.isVariant(CMISObjectVariant.CURRENT_VERSION)) { throw new CmisInvalidArgumentException("Stream id is invalid: " + streamId + ", expected variant " + CMISObjectVariant.CURRENT_VERSION + ", got variant " + streamInfo.getObjectVariant()); } streamNodeRef = streamInfo.getNodeRef(); type = streamInfo.getType(); checkDocumentTypeForContent(type); } // get the stream now try { ContentReader contentReader = contentService.getReader(streamNodeRef, ContentModel.PROP_CONTENT); if (contentReader == null) { throw new CmisConstraintException("Document has no content!"); } result.setMimeType(contentReader.getMimetype()); long contentSize = contentReader.getSize(); if ((offset == null) && (length == null)) { result.setStream(contentReader.getContentInputStream()); result.setLength(BigInteger.valueOf(contentSize)); publishReadEvent(streamNodeRef, info.getName(), result.getMimeType(), contentSize, contentReader.getEncoding(), null); } else { long off = (offset == null ? 0 : offset.longValue()); long len = (length == null ? contentSize : length.longValue()); if (off + len > contentSize) { len = contentReader.getSize() - off; } result.setStream(new RangeInputStream(contentReader.getContentInputStream(), off, len)); result.setLength(BigInteger.valueOf(len)); publishReadEvent(streamNodeRef, info.getName(), result.getMimeType(), contentSize, contentReader.getEncoding(), off+" - "+len); } } catch (Exception e) { if (e instanceof CmisBaseException) { throw (CmisBaseException) e; } else { StringBuilder msg = new StringBuilder("Failed to retrieve content: " + e.getMessage()); Throwable cause = e.getCause(); if(cause != null) { // add the cause to the CMIS exception msg.append(", "); msg.append(cause.getMessage()); } throw new CmisRuntimeException(msg.toString(), e); } } return result; }
Example #16
Source File: AlfrescoCmisExceptionInterceptor.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public Object invoke(MethodInvocation mi) throws Throwable { try { return mi.proceed(); } catch (Exception e) { // We dig into the exception to see if there is anything of interest to CMIS Throwable cmisAffecting = ExceptionStackUtil.getCause(e, EXCEPTIONS_OF_INTEREST); if (cmisAffecting == null) { // The exception is not something that CMIS needs to handle in any special way if (e instanceof CmisBaseException) { throw (CmisBaseException) e; } else { throw new CmisRuntimeException(e.getMessage(), e); } } // All other exceptions are carried through with full stacks but treated as the exception of interest else if (cmisAffecting instanceof AuthenticationException) { throw new CmisPermissionDeniedException(cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof CheckOutCheckInServiceException) { throw new CmisVersioningException("Check out failed: " + cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof FileExistsException) { throw new CmisContentAlreadyExistsException("An object with this name already exists: " + cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof IntegrityException) { throw new CmisConstraintException("Constraint violation: " + cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof AccessDeniedException) { throw new CmisPermissionDeniedException("Permission denied: " + cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof NodeLockedException) { throw new CmisUpdateConflictException("Update conflict: " + cmisAffecting.getMessage(), e); } else { // We should not get here, so log an error but rethrow to have CMIS handle the original cause logger.error("Exception type not handled correctly: " + e.getClass().getName()); throw new CmisRuntimeException(e.getMessage(), e); } } }
Example #17
Source File: LDCmisService.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
/** * Return the most recent events regarding a document * * @param repositoryId * @return The getTime() of the latest date */ protected String getLatestChangeLogToken(String repositoryId) { log.debug("** getLatestChangeLogToken: {}", repositoryId); try { ContextProperties settings = Context.get().getProperties(); if (!"true".equals(settings.getProperty("cmis.changelog"))) { return null; } LDRepository repo = repositories.get(repositoryId); String tenantIdStr = Long.toString(repo.getRoot().getTenantId()); StringBuffer query = new StringBuffer( "SELECT MAX(ld_date) FROM ld_history WHERE ld_deleted=0 AND ld_tenantid="); query.append(tenantIdStr); query.append(" AND ld_event IN ('"); query.append(DocumentEvent.STORED); query.append("','"); query.append(DocumentEvent.CHECKEDIN); query.append("','"); // query.append(DocumentEvent.CHANGED);// this happens when metadata are changed, it is not so relevant for LDSynch so to improve performance we commented it // query.append("','"); query.append(DocumentEvent.MOVED); query.append("','"); query.append(DocumentEvent.RENAMED); query.append("','"); query.append(DocumentEvent.DELETED); query.append("')"); //log.debug("Query: {}", query.toString()); Timestamp latestDate = (Timestamp) historyDao.queryForObject(query.toString(), Timestamp.class); StringBuffer query2 = new StringBuffer( "SELECT MAX(ld_date) FROM ld_folder_history WHERE ld_deleted=0 AND ld_tenantid="); query2.append(tenantIdStr); query2.append(" AND ld_event IN ('"); query2.append(FolderEvent.CREATED); query2.append("','"); query2.append(FolderEvent.RENAMED); query2.append("','"); query2.append(FolderEvent.MOVED); query2.append("','"); query2.append(FolderEvent.DELETED); query2.append("')"); //log.debug("Query: {}", query2.toString()); Timestamp latestFolderDate = (Timestamp) historyDao.queryForObject(query2.toString(), Timestamp.class); if (latestDate == null && latestFolderDate == null) { //log.debug("latestDate == null, return 0"); return "0"; } else { // log.debug("latestDate.getTime(): {}" ,latestDate.getTime()); // return Long.toString(latestDate.getTime()); log.debug("latestDate.getTime(): {}", latestDate.getTime()); log.debug("latestFolderDate.getTime(): {}", latestFolderDate.getTime()); Timestamp myDate = getLatestTimestamp(latestDate, latestFolderDate); log.debug("myDate.getTime(): {}" ,myDate.getTime()); return Long.toString(myDate.getTime()); } } catch (Throwable e) { log.error(e.getMessage(), e); throw new CmisRuntimeException(e.toString(), e); } }