public class OCUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(ContentResult result)
Returns if the given result is null, otherwise calls
closeQuietly(EnhancedCompleteObject)
with result.getObject() |
static void |
closeQuietly(EnhancedCompleteObject eco)
Returns if the given eco is null, otherwise calls
closeQuietly(EnhancedObjectContent)
with eco.getContent() |
static void |
closeQuietly(EnhancedObjectContent content)
Returns if the given content is null, otherwise attempts to close the
InputStream on EnhancedObjectContent.getContent() . |
static java.util.List<OpenContentObject> |
compareOCOs(java.util.List<OpenContentObject> tempResults,
java.lang.String sortAttr,
boolean ascending)
This method returns the same list that is passed in of Open Content Objects and returns them sorted by the attribtue that is passed in
|
static void |
convertEOP(EnhancedObjectProperty p,
java.util.Map<java.lang.String,java.lang.Object> targetMap) |
static void |
convertPropertiesToRepoName(EnhancedObjectProperty[] properties,
ObjectTypeConfig defaultOtc)
Convenience method to convert an array of object properties
|
static void |
convertPropertyToRepoName(EnhancedObjectProperty property,
ObjectTypeConfig defaultOtc)
Converts the given property bean to contain the repo name in the 'name' attribute rather than
the bean name.
|
static EnhancedObjectContent |
createContent(org.springframework.web.multipart.MultipartFile f,
java.io.InputStream is,
java.lang.String objectName,
long objectSize,
java.lang.String fileExtension)
Creates an EnhancedObjectContent object with a set content type and mime type, name and actual content data handler.
|
static ContentResult |
createFolderByPath(java.lang.String ticket,
java.lang.String path,
java.lang.String folderTypeBeanName)
Helper method to create a folder at the specified path.
|
static java.lang.String |
dataHandlerToString(javax.activation.DataHandler dh) |
static boolean |
doesRenditionTypeExist(java.lang.String ticket,
java.lang.String objectId,
java.lang.String mimetype) |
static OpenContentObject |
enhancedCompleteObjectToOpenContentObject(java.lang.String ticket,
EnhancedCompleteObject eco)
Converts an EnhancedCompleteObject to an OpenContentObject.
|
static void |
ensureObjectNotLocked(java.lang.String ticket,
java.lang.String objectId)
Ensures that the given object is not locked.
|
static EnhancedObjectProperty |
findEnhancedObjectProperty(EnhancedObjectProperty[] columns,
java.lang.String columnName)
Deprecated.
use bean names where possible instead of repo names
|
static EnhancedObjectProperty |
findEnhancedObjectPropertyByBeanName(EnhancedObjectProperty[] columns,
java.lang.String type,
java.lang.String beanName)
Returns the EnhancedObjectProperty object with the given OC bean name from the given columns array, null-safe and returns null if name not found.
|
static ContentResult |
findOrCreateFolder(java.lang.String ticket,
java.lang.String parentFolderId,
java.lang.String subFolderName,
java.lang.String folderTypeBeanName)
Finds or creates a folder.
|
static ContentResult |
findOrCreateFolderAsAdmin(java.lang.String ticket,
java.lang.String parentFolderId,
java.lang.String subFolderName,
java.lang.String folderTypeBeanName)
Finds or creates a folder.
|
static ContentResult |
findOrCreateFolderByPath(java.lang.String ticket,
java.lang.String path,
java.lang.String folderTypeBeanName)
Finds or creates a folder by folder path.
|
static ContentResult |
findOrCreateFolderByPathAsAdmin(java.lang.String ticket,
java.lang.String path,
java.lang.String folderTypeBeanName)
Finds or creates a folder.
|
static java.util.List<java.lang.String> |
getDocsWithoutRenditions(java.lang.String ticket,
java.util.List<java.lang.String> objectIds,
java.lang.String renditionMimetype)
Get a list of Object Ids of all docs in passed in list of docs that do not yet have a rendition
|
static java.lang.String |
getDocumentNameByObjectId(java.lang.String ticket,
java.lang.String objectId)
Takes the objectId of the current repo object and returns the document name
|
static java.lang.String |
getDocumentPropertyByObjectId(java.lang.String ticket,
java.lang.String objectId,
java.lang.String property)
Takes the objectId of the current repo object and returns the specified property
IMPORTANT: Dont overuse this.
|
static java.lang.String |
getExtensionByMimeType(java.lang.String mimetype)
Returns the related file extension for the provided mimetype.
|
static ContentResult |
getFolderAtPath(java.lang.String ticket,
java.lang.String path)
Helper method to get the folder at the specified path.
|
static java.lang.String |
getMimeTypeFromFileContent(java.io.File fileContent)
Gets the mimetype of the file based on the file content
|
static java.lang.String |
getMimeTypeFromFileName(java.lang.String fileName)
Gets the mimetype of the file based on the file name.
|
static java.util.ArrayList<java.lang.String> |
getObjectIdsInCollection(java.lang.String ticket,
java.lang.String collectionId,
java.lang.String collectionRelation,
java.lang.String collectionSortProp,
boolean sortAsc)
Get all the objectIds in the collection
|
static java.lang.String |
getOCNameFromRepoName(java.lang.String repoName)
Takes in a repo name and returns the coresponding OCName
|
static java.lang.String |
getOCObjectTypeName(java.lang.String ticket,
java.lang.String objectId)
Returns the OC bean name of the parameterized objectId's type.
|
static OCTypeDefinition |
getOCTypeDefinition(java.lang.String ticket,
java.lang.String objectId)
Get the OC type definition for the given object
|
static java.util.List<OpenContentObject> |
getSiblingRelations(java.lang.String ticket,
java.lang.String objectId,
java.lang.String relationName)
Returns a list of OpenContentObject objects for siblings
|
static ObjectTypeConfig |
getTypeConfigByBeanName(java.lang.String typeName)
Get the object type config for the type bean specified.
|
static java.lang.String |
getTypeRepoNameByBeanName(java.lang.String typeName)
Gets the type repo name based on the bean name.
|
static java.lang.String |
getVersionNumber(OpenContentObject oco)
Gets the version number property as a
String from the given
OpenContentObject . |
static java.lang.String |
getVersionNumber(java.lang.String[] versionLabels)
Gets the version number based on the array of version labels.
|
static void |
initializebadObjectNameCharacters() |
static boolean |
isAnnotated(java.lang.String ticket,
java.lang.String objectId)
Checks to see if the document is annotated based on objectId passed in
|
static boolean |
isTypeOrSubtypeOf(java.lang.String ticket,
java.lang.String ocObjectTypeA,
java.lang.String ocObjectTypeB)
If ocObjectTypeA is the same type or a subtype of ocObjectTypeB, returns true.
|
static boolean |
isTypeOrSubTypeOfExpensive(java.lang.String ticket,
java.lang.String objectId,
java.lang.String objectType)
Returns true if the object given is a type or subtype of the objectType passed in
|
static <T> T |
jsonToPojo(java.lang.String json,
java.lang.Class<T> classType)
Converts a JSON string to a POJO
|
static EnhancedCompleteObject |
openContentObjectToEnhancedCompleteObject(java.lang.String ticket,
OpenContentObject oco)
Converts an OpenContentObject to an EnhancedCompleteObject.
|
static java.lang.String |
pojoToJSON(java.lang.Object pojo)
Converts a POJO object to a JSON String
|
static ContentResult |
recursivelyFindOrCreateFolderByPath(java.lang.String ticket,
java.lang.String path,
java.lang.String folderTypeBeanName)
Finds or creates a folder recursively by folder path.
|
static ContentResult |
recursivelyFindOrCreateFolderByPath(java.lang.String ticket,
java.lang.String path,
java.lang.String[] folderTypeBeanName,
java.lang.Integer depth)
Finds or creates a folder recursively by folder path but allows you to pass in array of custom folder types.
|
static java.lang.String |
resolveAndSetProperties(OpenContentObject oco,
java.util.Map<java.lang.String,java.lang.Object> propertiesToSet,
java.lang.String fileExtension,
boolean forceFileExtensionInObjectName)
Utility method to set a map of properties on the provided OCO.
|
static java.lang.String |
resolveObjectNameWithFileExtension(java.lang.String objectName,
java.lang.String fileExtension,
boolean forceFileExtensionInObjectName)
Resolves the objectName by either appending or removing the provided fileExtension depending on the value of forceFileExtensionIntoObjectName.
|
static void |
sanitizeObjectName(java.lang.String objectName) |
static javax.activation.DataHandler |
stringToDataHandler(java.lang.String str)
Converts a string to a DataHandler
|
static java.lang.String |
toLowerCaseByCharacter(java.lang.String stringToLower)
Same thing as the
toUpperCaseByCharacter(String) function, just does lowercase |
static java.lang.String |
toUpperCaseByCharacter(java.lang.String stringToUpper)
Converts an string to upper case by going character by character using
Character.toUpperCase(char) , instead of String.toUpperCase()
Should only use this if you have a reason to, meaning you don't want some of the specific stuff String.toUpperCase() does (locale stuff, 1-many mappings, etc.)
Also if you find a util method out there that does this we can get rid of it, all the ones I know of use String.toUpperCase() |
static boolean |
userOwnsTicket(java.lang.String ticket,
java.lang.String name)
Verifies that the username is the same as the one on the ticket.
|
static void |
waitForDocsToFinishRenditioning(java.lang.String ticket,
java.util.List<java.lang.String> docsWithoutRenditions,
int sleepTimeForBusyWait,
boolean throwErrorIfRenditionFails)
Waits until all the docs in a collection have a pdf rendition
|
@Deprecated public static EnhancedObjectProperty findEnhancedObjectProperty(EnhancedObjectProperty[] columns, java.lang.String columnName)
columns
- columnName
- the column REPO name#findEnhancedObjectPropertyByBeanName(EnhancedObjectProperty[], String)
public static EnhancedObjectProperty findEnhancedObjectPropertyByBeanName(EnhancedObjectProperty[] columns, java.lang.String type, java.lang.String beanName)
columns
- the properties you're looking throughtype
- the object type name (either bean name or repo name)beanName
- the bean namepublic static java.util.List<OpenContentObject> compareOCOs(java.util.List<OpenContentObject> tempResults, java.lang.String sortAttr, boolean ascending)
tempResults
- This is the list of results that is passed in from the querysortAttr
- The attribute set from "Attribute Search" within search configascending
- Ascending sort order or descendingpublic static ObjectTypeConfig getTypeConfigByBeanName(java.lang.String typeName)
typeBeanName
- the type bean name or repo namepublic static java.lang.String getTypeRepoNameByBeanName(java.lang.String typeName)
typeBeanName
- the bean name or repo namepublic static void convertPropertiesToRepoName(EnhancedObjectProperty[] properties, ObjectTypeConfig defaultOtc)
properties
- the properties arraydefaultOtc
- the default type config to use if a property in the array doesn't have a table setconvertPropertyToRepoName(EnhancedObjectProperty, ObjectTypeConfig)
public static void convertPropertyToRepoName(EnhancedObjectProperty property, ObjectTypeConfig defaultOtc)
property
- the property to convertdefaultOtc
- the default type config to use if the property doesn't have a table setpublic static void ensureObjectNotLocked(java.lang.String ticket, java.lang.String objectId) throws OCObjectLockedException
ticket
- authentication ticketobjectId
- the object to checkOCObjectLockedException
- if the object is lockedpublic static EnhancedCompleteObject openContentObjectToEnhancedCompleteObject(java.lang.String ticket, OpenContentObject oco)
ticket
- auth ticketoco
- the OpenContentObject to convertpublic static OpenContentObject enhancedCompleteObjectToOpenContentObject(java.lang.String ticket, EnhancedCompleteObject eco)
ticket
- auth ticketeco
- The EnahncedCompleteObject to convertpublic static void convertEOP(EnhancedObjectProperty p, java.util.Map<java.lang.String,java.lang.Object> targetMap) throws java.lang.NoSuchFieldException
p
- targetMap
- - Method does .put(ocName, valueObject) into this mapjava.lang.NoSuchFieldException
- - Thrown when field isn't found in dictionary service. Calling code should catch and
decide if this should be fatalpublic static java.lang.String getOCNameFromRepoName(java.lang.String repoName) throws java.lang.NoSuchFieldException
repoName
- java.lang.NoSuchFieldException
public static java.lang.String pojoToJSON(java.lang.Object pojo) throws com.fasterxml.jackson.databind.JsonMappingException, OCException
pojo
- the POJOcom.fasterxml.jackson.databind.JsonMappingException
OCException
public static <T> T jsonToPojo(java.lang.String json, java.lang.Class<T> classType) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
json
- classType
- com.fasterxml.jackson.core.JsonParseException
com.fasterxml.jackson.databind.JsonMappingException
java.io.IOException
public static javax.activation.DataHandler stringToDataHandler(java.lang.String str)
str
- public static java.lang.String dataHandlerToString(javax.activation.DataHandler dh) throws java.io.IOException
dh
- java.io.IOException
public static boolean doesRenditionTypeExist(java.lang.String ticket, java.lang.String objectId, java.lang.String mimetype)
public static ContentResult findOrCreateFolder(java.lang.String ticket, java.lang.String parentFolderId, java.lang.String subFolderName, java.lang.String folderTypeBeanName)
ticket
- authentication ticketparentFolderId
- the parent folder idsubFolderName
- the subfolder to get to createfolderTypeBeanName
- the type of folder to create (if one is created). NOTE: This is the bean name, not the repo name. If null, the
base Folder bean name will be used.public static ContentResult findOrCreateFolderAsAdmin(java.lang.String ticket, java.lang.String parentFolderId, java.lang.String subFolderName, java.lang.String folderTypeBeanName)
ticket
- authentication ticketparentFolderId
- the parent folder idsubFolderName
- the subfolder to get to createfolderTypeBeanName
- the type of folder to create (if one is created). NOTE: This is the bean name, not the repo name. If null, the
base Folder bean name will be used.public static ContentResult findOrCreateFolderByPathAsAdmin(java.lang.String ticket, java.lang.String path, java.lang.String folderTypeBeanName)
ticket
- authentication ticketpath
- the pathfolderTypeBeanName
- the type of folder to create (if one is created). NOTE: This is the bean name, not the repo name. If null, the
base Folder bean name will be used.public static ContentResult findOrCreateFolderByPath(java.lang.String ticket, java.lang.String path, java.lang.String folderTypeBeanName)
/one/two/threeFolders one and two must exist. This method will return folder three if it exists, or create it and return the new folder object. If folder two does not exist at /one/two, this method will throw an exception/
ticket
- authentication ticketpath
- the path of the folder to createfolderTypeBeanName
- the type of folder to create (if one is created). Note this is the bean name, not repo name.public static ContentResult recursivelyFindOrCreateFolderByPath(java.lang.String ticket, java.lang.String path, java.lang.String folderTypeBeanName)
/one/two/threeif folders two and three do not exist, it will create folders two and three. For Doucmentum, we cannot create cabinets, only folders within preexisting cabinets
ticket
- authentication ticketpath
- the path of the folder to createfolderTypeBeanName
- the type of folder to create (if one is created). Note this is the bean name, not repo name.public static ContentResult recursivelyFindOrCreateFolderByPath(java.lang.String ticket, java.lang.String path, java.lang.String[] folderTypeBeanName, java.lang.Integer depth)
/one/two/threeand String[] of {"Folder", "Folder", "Custom Folder"} if folders two and three do not exist, it will create folders two and three. two as a Folder and three as a Custom Folder For Doucmentum, we cannot create cabinets, only folders within preexisting cabinets
ticket
- authentication ticketpath
- the path of the folder to createfolderTypeBeanName
- an array of types of folders to create (if one is created). Note this is the bean names, not repo names.public static ContentResult getFolderAtPath(java.lang.String ticket, java.lang.String path)
ticket
- path
- public static ContentResult createFolderByPath(java.lang.String ticket, java.lang.String path, java.lang.String folderTypeBeanName)
ticket
- path
- folderTypeBeanName
- public static java.lang.String getVersionNumber(java.lang.String[] versionLabels)
versionLabels
- the list of version labelspublic static java.lang.String getVersionNumber(OpenContentObject oco)
String
from the given
OpenContentObject
. This method is handy since some ECM systems
store the version number as a string, while others as a repeating string.
If the OCO contains a version number as a list, the getVersionNumber(String[])
method will be used to extract the actual version number. Otherwise, the
version number string will be returnedoco
- the OpenContentObject
public static java.lang.String getOCObjectTypeName(java.lang.String ticket, java.lang.String objectId)
ticket
- objectId
- public static OCTypeDefinition getOCTypeDefinition(java.lang.String ticket, java.lang.String objectId)
ticket
- authentication IDobjectId
- the object to retrieve the type forOCTypeDefinition
for the given object's typepublic static boolean isTypeOrSubTypeOfExpensive(java.lang.String ticket, java.lang.String objectId, java.lang.String objectType)
ticket
- objectId
- objectType
- - OC objectTypepublic static boolean isTypeOrSubtypeOf(java.lang.String ticket, java.lang.String ocObjectTypeA, java.lang.String ocObjectTypeB)
ticket
- ocObjectTypeA
- ocObjectTypeB
- public static java.lang.String resolveObjectNameWithFileExtension(java.lang.String objectName, java.lang.String fileExtension, boolean forceFileExtensionInObjectName)
For example: resolveObjectNameWithFileExtension("testdoc", "pdf", true) => testdoc.pdf resolveObjectNameWithFileExtension("testdoc.test", "pdf", true) => testdoc.test.pdf resolveObjectNameWithFileExtension("testdoc.pdf", "pdf", false) => testdoc resolveObjectNameWithFileExtension("testdoc.docx", "pdf", false) => testdoc.docx [this is expected, if you want to remove "docx", fileExtension must equal "docx"]
objectName
- the objectName value to either append or remove the provided fileExtension fromfileExtension
- the fileExtension value to either append or removeforceFileExtensionInObjectName
- true to append the fileExtension to the objectName, false to remove itpublic static java.lang.String resolveAndSetProperties(OpenContentObject oco, java.util.Map<java.lang.String,java.lang.Object> propertiesToSet, java.lang.String fileExtension, boolean forceFileExtensionInObjectName)
oco
- the OCO object to set the properties on.propertiesToSet
- the properties map to set on the OCO.fileExtension
- the file extension to either set on or remove from the objectName value.forceFileExtensionInObjectName
- true to force the file extension to be on the objectName value, false to remove the file extension.public static EnhancedObjectContent createContent(org.springframework.web.multipart.MultipartFile f, java.io.InputStream is, java.lang.String objectName, long objectSize, java.lang.String fileExtension) throws java.io.IOException
f
- the multipart file object to use for getting the content type if the file extension is not defined in our content formats map.is
- the input stream to use for the data handler set on the content.objectName
- the objectName to set as the content name.fileExtension
- the fileExtension to use for looking up the content format in our extensions map.java.io.IOException
- if there is an error reading the provided input stream.public static java.lang.String getExtensionByMimeType(java.lang.String mimetype)
OCRuntimeException
is thrown.mimetype
- the mimetype to get the related file extension for.public static java.util.List<OpenContentObject> getSiblingRelations(java.lang.String ticket, java.lang.String objectId, java.lang.String relationName)
ticket
- - ticket from requestobjectId
- - idrelationName
- - relation namepublic static void sanitizeObjectName(java.lang.String objectName)
public static void initializebadObjectNameCharacters()
public static boolean userOwnsTicket(java.lang.String ticket, java.lang.String name)
ticket
- path
- name
- public static java.lang.String getDocumentNameByObjectId(java.lang.String ticket, java.lang.String objectId)
ticket
- A valid OC ticket.objectId
- The id of the repo object that is being saved to.public static java.lang.String getMimeTypeFromFileName(java.lang.String fileName)
fileName.
- The filename of the file we are trying to get the mimetype for.public static java.lang.String getMimeTypeFromFileContent(java.io.File fileContent)
fileContent.
- The file we are trying to get the mimetype for.public static boolean isAnnotated(java.lang.String ticket, java.lang.String objectId)
ticket.
- objectId
- public static void closeQuietly(ContentResult result)
closeQuietly(EnhancedCompleteObject)
with result.getObject()
result
- the ContentResult
public static void closeQuietly(EnhancedCompleteObject eco)
closeQuietly(EnhancedObjectContent)
with eco.getContent()
eco
- public static void closeQuietly(EnhancedObjectContent content)
InputStream
on EnhancedObjectContent.getContent()
. If any
errors occur, this method simply logs a warning and returns.content
- the EnhancedObjectContent
public static java.lang.String getDocumentPropertyByObjectId(java.lang.String ticket, java.lang.String objectId, java.lang.String property)
ticket
- objectId
- property
- public static java.util.ArrayList<java.lang.String> getObjectIdsInCollection(java.lang.String ticket, java.lang.String collectionId, java.lang.String collectionRelation, java.lang.String collectionSortProp, boolean sortAsc)
ticket
- collectionId
- - objectId of the collectioncollectionRelation
- - relation namecollectionSortProp
- - property to sort all the docs onsortAsc
- - only used if we pass in a collectionSortProp, true if we want to sort in ascending order, false if we want to sort in dsc orderpublic static java.util.List<java.lang.String> getDocsWithoutRenditions(java.lang.String ticket, java.util.List<java.lang.String> objectIds, java.lang.String renditionMimetype)
ticket
- objectIds
- - objectIds to check for renditionsrenditionMimetype
- - mimetime we want the rendition to be ofpublic static void waitForDocsToFinishRenditioning(java.lang.String ticket, java.util.List<java.lang.String> docsWithoutRenditions, int sleepTimeForBusyWait, boolean throwErrorIfRenditionFails)
ticket
- docsWithoutRenditions
- - Object Ids of all docs in passed in list of docs that do not yet have a renditionsleepTimeForBusyWait-
- time to wait before checkingthrowErrorIfRenditionFails
- - true if we want to throw an error if a rendition Failspublic static java.lang.String toUpperCaseByCharacter(java.lang.String stringToUpper)
Character.toUpperCase(char)
, instead of String.toUpperCase()
Should only use this if you have a reason to, meaning you don't want some of the specific stuff String.toUpperCase()
does (locale stuff, 1-many mappings, etc.)
Also if you find a util method out there that does this we can get rid of it, all the ones I know of use String.toUpperCase()
stringToUpper
- The string to convert to upper case character by characterpublic static java.lang.String toLowerCaseByCharacter(java.lang.String stringToLower)
toUpperCaseByCharacter(String)
function, just does lowercasestringToLower
- The string to convert to lower case character by character