Class FMUtils


  • public class FMUtils
    extends java.lang.Object
    • Constructor Detail

      • FMUtils

        public FMUtils()
    • Method Detail

      • getMetadataNode

        public static javax.jcr.Node getMetadataNode​(javax.jcr.Session session,
                                                     java.lang.String formPath,
                                                     boolean create)
                                              throws FormsMgrException
        Throws:
        FormsMgrException
      • getAnalyticsDataNode

        public static javax.jcr.Node getAnalyticsDataNode​(javax.jcr.Node formNode,
                                                          boolean create)
                                                   throws FormsMgrException
        Throws:
        FormsMgrException
      • getFMResourceFromAF

        public static Resource getFMResourceFromAF​(Resource adaptiveForm)
      • isAdaptiveForm

        public static boolean isAdaptiveForm​(Resource resource)
      • isThemeClientLib

        public static boolean isThemeClientLib​(javax.jcr.Node assetNode)
                                        throws FormsMgrException
        Parameters:
        assetNode - a non null node
        Returns:
        true if the given node is of type FMConstants.CQ_CLIENTLIBRARY_FOLDER and FMConstants.GUIDE_COMPONENT_TYPE property's value is FMConstants.THEME_GUIDE_COMPONENT_TYPE_VALUE. false otherwise
        Throws:
        FormsMgrException
      • isMultichannelDocument

        public static boolean isMultichannelDocument​(javax.jcr.Session session,
                                                     java.lang.String path)
                                              throws FormsMgrException
        Throws:
        FormsMgrException
      • isDocumentChannel

        public static boolean isDocumentChannel​(@Nonnull
                                                ResourceResolver resourceResolver,
                                                java.lang.String path)
        Returns whether a cq:Page is a Document channel or not
        Parameters:
        resourceResolver -
        path - Path to the Channel cq:Page
        Returns:
      • getDocumentPagePath

        public static java.lang.String getDocumentPagePath​(java.lang.String channelPath)
        Returns the Document page path
        Parameters:
        channelPath - Path to the Channel cq:Page
        Returns:
      • hasProperty

        public static boolean hasProperty​(javax.jcr.Session session,
                                          java.lang.String path,
                                          java.lang.String propertyName)
                                   throws FormsMgrException
        Throws:
        FormsMgrException
      • getNodeProperty

        public static javax.jcr.Property getNodeProperty​(java.lang.String propertyName,
                                                         javax.jcr.Node node)
                                                  throws FormsMgrException
        Throws:
        FormsMgrException
      • getXDPRefPath

        public static java.lang.String getXDPRefPath​(javax.jcr.Session session,
                                                     java.lang.String guidePath)
                                              throws FormsMgrException
        Throws:
        FormsMgrException
      • getDORRefPath

        public static java.lang.String getDORRefPath​(javax.jcr.Session session,
                                                     java.lang.String guidePath)
                                              throws FormsMgrException
        Throws:
        FormsMgrException
      • getMetaTemplateRefPath

        public static java.lang.String getMetaTemplateRefPath​(javax.jcr.Session session,
                                                              java.lang.String guidePath)
                                                       throws FormsMgrException
        Throws:
        FormsMgrException
      • getXSDRefPath

        public static java.lang.String getXSDRefPath​(javax.jcr.Session session,
                                                     java.lang.String guidePath)
                                              throws FormsMgrException
        Throws:
        FormsMgrException
      • getSchemaRefPath

        public static java.lang.String getSchemaRefPath​(javax.jcr.Session session,
                                                        java.lang.String guidePath)
                                                 throws FormsMgrException
        Throws:
        FormsMgrException
      • createGuideRenderURL

        public static java.util.Map<java.lang.String,​java.lang.String> createGuideRenderURL​(javax.jcr.Node guideNode,
                                                                                                  java.lang.String sampleDataId,
                                                                                                  javax.jcr.Session session)
                                                                                           throws FormsMgrException
        Throws:
        FormsMgrException
      • createMulichannelDocumentRenderURL

        public static java.util.Map<java.lang.String,​java.lang.String> createMulichannelDocumentRenderURL​(javax.jcr.Node assetNode,
                                                                                                                java.lang.String sampleDataId,
                                                                                                                javax.jcr.Session session,
                                                                                                                java.lang.String channelType)
                                                                                                         throws FormsMgrException
        Throws:
        FormsMgrException
      • createFormsetRenderURLParams

        public static java.util.Map<java.lang.String,​java.lang.String> createFormsetRenderURLParams​(javax.jcr.Node formNode,
                                                                                                          java.lang.String type,
                                                                                                          java.lang.String submitUrl,
                                                                                                          java.lang.String profile,
                                                                                                          java.lang.String sampleDataId,
                                                                                                          javax.jcr.Session session)
                                                                                                   throws FormsMgrException
        Throws:
        FormsMgrException
      • deleteTempArchives

        public static void deleteTempArchives​(javax.jcr.Session session)
                                       throws FormsMgrException
        Deletes temp archives created in CRX during uploadForm. If a temp archive remains in the repository for more than a certain duration, the DeleteTempArchiveScheduler will call this function and delete it.
        Parameters:
        session - - Session session
        Throws:
        FormsMgrException
      • getFolderNode

        public static javax.jcr.Node getFolderNode​(javax.jcr.Session session,
                                                   java.lang.String rootNodePath,
                                                   boolean create,
                                                   java.lang.String folderType)
                                            throws FormsMgrException
        Throws:
        FormsMgrException
      • getPagePathFromAsset

        public static java.lang.String getPagePathFromAsset​(java.lang.String assetPath)
        This function returns Page path from Asset path for Adaptive Assets ie : Guide, AF Fragment, Adaptive Document, Multichannel Document
        Parameters:
        assetPath - path of the asset
      • getAssetPathFromPage

        public static java.lang.String getAssetPathFromPage​(java.lang.String pagePath)
        This function returns Asset path from Page path for Adaptive Pages ie : Guide, AF Fragment, Adaptive Document
        Parameters:
        pagePath - path of the asset
      • getClosestNodeUpInHierarchy

        public static Resource getClosestNodeUpInHierarchy​(ResourceResolver resolver,
                                                           java.lang.String path,
                                                           java.lang.String inputPropertyName,
                                                           java.lang.String inputPropertyValue,
                                                           boolean includeCurrentNode)
                                                    throws FormsMgrException
        This function returns first node resource encountered up in the hierarchy that has given property value of the given property name.
        Parameters:
        resolver -
        path -
        inputPropertyName -
        inputPropertyValue -
        includeCurrentNode -
        Throws:
        FormsMgrException
      • getLastModifiedOrCreated

        public static long getLastModifiedOrCreated​(javax.jcr.Session session,
                                                    java.lang.String assetPath)
                                             throws FormsMgrException
        Parameters:
        session -
        assetPath -
        Returns:
        lastmodified time or created time or -1 if cant read property, but node exists
        Throws:
        FormsMgrException - if cant get node
      • getLastUpdatedPropertyOnNode

        public static long getLastUpdatedPropertyOnNode​(javax.jcr.Node node)
                                                 throws java.lang.NullPointerException,
                                                        javax.jcr.RepositoryException
        Throws:
        java.lang.NullPointerException
        javax.jcr.RepositoryException
      • getCreatedPropertyOnNode

        public static long getCreatedPropertyOnNode​(javax.jcr.Node node)
                                             throws java.lang.NullPointerException,
                                                    javax.jcr.RepositoryException
        Throws:
        java.lang.NullPointerException
        javax.jcr.RepositoryException
      • getFormsMgrException

        public static FormsMgrException getFormsMgrException​(java.lang.Exception e)
      • unscheduleJob

        public static void unscheduleJob​(JobManager jobManager,
                                         java.lang.String formPath,
                                         java.lang.String replicationAtribute)
      • getRootLevelAssetType

        public static java.lang.String getRootLevelAssetType​(javax.jcr.Session session,
                                                             java.lang.String assetPath)
                                                      throws javax.jcr.RepositoryException
        This method is used to deduce the type of the root level folder in which the asset with the specified asset path lies. It will return 'lcApplication' if asset lies inside an LC Application, 'lcFolder' if inside a general folder, its asset type if the asset lies in the shadow root node and null if the asset does not exist or if the path is of the shadow root node itself.
        Parameters:
        session - CRX session to be used
        assetPath - Path of the asset for which to deduce which type of root folder it belongs to.
        Throws:
        javax.jcr.RepositoryException
      • getBytesFromInputStream

        public static byte[] getBytesFromInputStream​(java.io.InputStream oInpStream)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • getFnDServiceUserSession

        public static javax.jcr.Session getFnDServiceUserSession​(SlingRepository repository)
                                                          throws javax.jcr.RepositoryException
        This function returns the session for fd-service system user.
        Parameters:
        repository -
        Returns:
        fnd-service system user session
        Throws:
        javax.jcr.RepositoryException
      • getFnDServiceUserResourceResolver

        public static ResourceResolver getFnDServiceUserResourceResolver​(ResourceResolverFactory resourceResolverFactory)
                                                                  throws LoginException
        This function returns the resource resolver for fd-service system user.
        Parameters:
        resourceResolverFactory -
        Returns:
        fnd-service system user resource resolver
        Throws:
        javax.jcr.RepositoryException
        LoginException
      • getFnDServiceUserResourceResolver

        public static ResourceResolver getFnDServiceUserResourceResolver​(ResourceResolverFactory resourceResolverFactory,
                                                                         java.lang.String subServiceName)
                                                                  throws LoginException
        This function returns the resource resolver for user mapped for provided subServiceName.
        Parameters:
        resourceResolverFactory -
        subServiceName -
        Returns:
        resource resolver for user mapped for provided subServiceName
        Throws:
        LoginException
      • canReplicate

        public static boolean canReplicate​(java.lang.String path,
                                           javax.jcr.Session session)
                                    throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • prepareJsonToCreateDAMAsset

        public static void prepareJsonToCreateDAMAsset​(ResourceResolver resourceResolver,
                                                       JSONObject inOutAssetJSON,
                                                       FMConstants.CoreAssetType assetType,
                                                       java.lang.String formPath,
                                                       java.lang.String formName)
                                                throws FormsMgrException
        Method to return DAM Asset json structure. This Json can be used with createAsset() API of FMCRUDService to create Asset. Session is not saved by this method.
        Parameters:
        resourceResolver -
        inOutAssetJSON -
        assetType -
        formPath -
        formName -
        Throws:
        FormsMgrException
      • removeAllMixinTypes

        public static void removeAllMixinTypes​(javax.jcr.Node node)
      • handleViewPrintNodeForDOR

        public static void handleViewPrintNodeForDOR​(java.lang.String dorType,
                                                     Resource guideContainerResource)
      • addSignEnabledFlag

        public static ModifiableValueMap addSignEnabledFlag​(JSONObject metadataProperties,
                                                            ModifiableValueMap mvm)
        method to enable sign flag if sign is enabled in template
        Parameters:
        metadataProperties -
        mvm -
        Returns:
      • getValidAFTemplate

        public static Template getValidAFTemplate​(ResourceResolver resourceResolver,
                                                  java.lang.String afTemplatePath,
                                                  java.lang.String assetPathSuffix)
                                           throws javax.jcr.RepositoryException
        Returns a Template object for the AF template path provided. Returns null if the template path is invalid.
        Parameters:
        resourceResolver -
        afTemplatePath -
        Returns:
        Template
        Throws:
        javax.jcr.RepositoryException
      • JsonToJcrNode

        public static void JsonToJcrNode​(javax.jcr.Node node,
                                         JSONObject jsonObject)
                                  throws JSONException,
                                         javax.jcr.RepositoryException
        Method to create jcr nodes from json. This behaves similar to sling post but doesn't include all the node types. Session is not saved by this method. jcr:mixinTypes property - it is skipped, if found, while setting properties on node. nt:File node - It is skipped(not added), if found, while adding nodes.
        Parameters:
        node - - Json structure will be mapped under this node.
        jsonObject -
        Throws:
        FormsMgrException
        JSONException
        javax.jcr.RepositoryException
      • moveNode

        public static void moveNode​(ResourceResolver resolver,
                                    java.lang.String sourceLocation,
                                    java.lang.String destinationLocation)
                             throws FormsMgrException
        This API is used to move node from source location to destination location
        Parameters:
        resolver -
        sourceLocation - - it contains the location of node which is to be moved
        destinationLocation - - it contains the location where node is to be moved
        Throws:
        FormsMgrException
      • getClientlibPath

        public static java.lang.String getClientlibPath​(javax.jcr.Node resourceNode)
                                                 throws FormsMgrException
        getClientlibPath This API is used to fetch client lib path by appending client lib location and asset name
        Parameters:
        resourceNode -
        Returns:
        clientLibPath
        Throws:
        FormsMgrException
      • getCreatorTool

        public static java.lang.String getCreatorTool​(javax.jcr.Session session,
                                                      java.lang.String path)
                                               throws FormsMgrException
        Throws:
        FormsMgrException
      • getPropertyAsString

        public static java.lang.String getPropertyAsString​(javax.jcr.Session session,
                                                           java.lang.String nodePath,
                                                           java.lang.String propertyName)
                                                    throws FormsMgrException
        Throws:
        FormsMgrException
      • getCategoryNameFromClientLibPath

        public static java.lang.String getCategoryNameFromClientLibPath​(java.lang.String clientLibPath)
        This API generates Category name from the theme clientlib path by appending relative path directory names separated by '.'
        Parameters:
        clientLibPath -
        Returns:
      • hasMixin

        public static boolean hasMixin​(javax.jcr.Node node,
                                       java.lang.String mixinName)
                                throws javax.jcr.RepositoryException
        This utility is to check whether mixinName exists at node or not
        Parameters:
        node -
        mixinName -
        Returns:
        boolean
        Throws:
        javax.jcr.RepositoryException
      • addMixin

        public static void addMixin​(javax.jcr.Node node,
                                    java.lang.String[] mixinNames)
                             throws FormsMgrException
        This utility is to add mixinNames at node
        Parameters:
        node -
        mixinNames -
        Throws:
        FormsMgrException
      • cleanUpReplicationInfo

        public static void cleanUpReplicationInfo​(javax.jcr.Session session,
                                                  java.lang.String path)
                                           throws FormsMgrException
        Throws:
        FormsMgrException
      • isValidAssetName

        public static boolean isValidAssetName​(java.lang.String assetName,
                                               java.lang.String pattern)
      • isValidFolderName

        public static boolean isValidFolderName​(java.lang.String folderName)
      • checkForExistingForms

        public static boolean checkForExistingForms​(java.lang.String assetPath,
                                                    javax.jcr.Session session,
                                                    java.lang.String rootPath)
                                             throws FormsMgrException,
                                                    javax.jcr.RepositoryException
        This API is used to parse through all the nodes in the hierarchy of the provided asset path and to check whether any of those nodes is an asset other than a folder.
        Parameters:
        assetPath -
        session -
        rootPath -
        Returns:
        boolean
        Throws:
        FormsMgrException
        javax.jcr.RepositoryException
      • isUserPartOfGroup

        public static boolean isUserPartOfGroup​(java.security.Principal userPrincipal,
                                                UserManager um,
                                                java.lang.String groupId)
                                         throws javax.jcr.RepositoryException
        Returns true if given userPrincipal is part of group
        Parameters:
        userPrincipal -
        um - reference to UserManager service
        Returns:
        boolean
        Throws:
        javax.jcr.RepositoryException
      • setLastModifiedTime

        public static void setLastModifiedTime​(java.lang.String formPath,
                                               ResourceResolver resolver)
        Parameters:
        formPath - dam asset path is expected
        resolver - resource resolver
      • notNulOrDefault

        public static <T> T notNulOrDefault​(T getValue,
                                            T defaultValue)
      • setAssetIdentifier

        public static void setAssetIdentifier​(javax.jcr.Node node,
                                              java.lang.String assetType,
                                              int validOrdinal)
                                       throws FormsMgrException
        This API sets the identifier at node.
        Parameters:
        node - at which identifier is to be set
        assetType - to be set as an identifier
        Throws:
        FormsMgrException
      • clientlibExists

        public static boolean clientlibExists​(java.lang.String clientlibCategoryName,
                                              HtmlLibraryManager htmlLibraryManager)
        API checks whether given client lib category does exist across aem or not
        Parameters:
        clientlibCategoryName -
        htmlLibraryManager -
        Returns:
      • getRequestParamValue

        public static java.lang.String getRequestParamValue​(RequestParameterMap paramMap,
                                                            java.lang.String param)
        This function retrieves string value of a request parameter.
        Parameters:
        paramMap -
        param -
        Returns:
        String value of the req parameter. null is no such param is found.
      • getTitle

        public static java.lang.String getTitle​(Resource resource)
        This API returns title of an asset. If title is empty then it returns name of node.
        Parameters:
        resource -
        Returns:
        String
      • getDisplayType

        public static java.lang.String getDisplayType​(Resource resource)
        This API returns display type of an Asset.
        Parameters:
        resource -
        Returns:
        String
      • getSize

        public static long getSize​(Resource resource)
        This API returns size of Asset. Its applicable for externally authored forms since they have a binary representation.
        Parameters:
        resource -
        Returns:
        long
      • getDescription

        public static java.lang.String getDescription​(Resource resource)
        This API returns description of an Asset.
        Parameters:
        resource -
        Returns:
        String
      • getStatus

        public static java.lang.String getStatus​(Resource resource)
        This API returns current status of an Asset.
        Parameters:
        resource -
        Returns:
        String
      • getLastModified

        public static long getLastModified​(Resource resource)
        This API returns last modified time of an Asset.
        Parameters:
        resource -
        Returns:
        long
      • getPrintChannelResource

        public static Resource getPrintChannelResource​(Resource resource)
                                                throws FormsMgrException
        Parameters:
        resource - a multichhanel document asset resource residing under /content/dam/formsanddocuments/ It's the responsibility of the caller to make sure that the resource refers to a valid multichannel document
        Returns:
        Resource representing Print channel of the multichannel document
        Throws:
        FormsMgrException - if any exception occurs while trying to load the resource and its hierarchy
      • getFormBytes

        public static byte[] getFormBytes​(javax.jcr.Session session,
                                          java.lang.String formPath)
                                   throws FormsMgrException
        This API fetches form binaries stored as jcr data at rendition content node
        Parameters:
        session -
        formPath -
        Returns:
        form binaries
        Throws:
        FormsMgrException
      • getOriginalRenditionNode

        public static javax.jcr.Node getOriginalRenditionNode​(javax.jcr.Node formNode,
                                                              boolean create)
                                                       throws java.lang.Exception
        This API returns original rendition node of given node. If create is true, and original rendition node does not exists, it creates new one.
        Parameters:
        formNode -
        create -
        Returns:
        original rendition node
        Throws:
        java.lang.Exception
      • makeNodeTrusted

        public static void makeNodeTrusted​(javax.jcr.Node node,
                                           boolean isTrusted)
                                    throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • isDORResolutionRequest

        public static boolean isDORResolutionRequest​(Resource resource,
                                                     java.util.Set supportedLocales)
      • getProbableDamAssetForRendition

        public static Resource getProbableDamAssetForRendition​(Resource rendition)
        climbs back up to the damAsset resource
        Parameters:
        rendition -
        Returns:
      • isVersionMatches

        public static boolean isVersionMatches​(java.lang.String versionToBeMatched,
                                               java.lang.String[] versions)
        Match a version against a list of versions
        Parameters:
        versionToBeMatched - - version which needs to be matched against list of versions
        versions - - list of versions
        Returns:
        boolean
      • isPreAF2

        public static boolean isPreAF2​(java.lang.String version)
        Check if fd:version value belongs to pre AF2 spec versions
        Parameters:
        version - - version
        Returns:
        boolean
      • isAF2

        public static boolean isAF2​(java.lang.String version)
        Check if fd:version value belongs to AF2 spec versions
        Parameters:
        version - - version
        Returns:
        boolean
      • isAF2WithCoreComponent

        public static boolean isAF2WithCoreComponent​(java.lang.String version)
        Check if fd:version value belongs to AF2 Form container core component (v2)
        Parameters:
        version - - version
        Returns:
        boolean
      • isAF2WithHeadlessComponent

        public static boolean isAF2WithHeadlessComponent​(java.lang.String version)
        Check if fd:version value belongs to AF2 Form container headless component (v1)
        Parameters:
        version - - version
        Returns:
        boolean
      • isImmutablePath

        public static boolean isImmutablePath​(java.lang.String path)
      • getSupportedLanguage

        public static java.lang.String getSupportedLanguage​(java.util.Locale locale,
                                                            GuideLocalizationService localizationService)
        Parameters:
        locale - current locale
        localizationService - Guidelocalizationservice instance
        Returns:
        current language if locale language is supported, else return en (English)
      • isPropertyProtected

        public static boolean isPropertyProtected​(javax.jcr.Node node,
                                                  java.lang.String propertyName)
                                           throws javax.jcr.RepositoryException
        Checks if a property is protected on a given node.
        Parameters:
        node - the node to check the property on
        propertyName - the name of the property to check
        Returns:
        true if the property is protected, false otherwise
        Throws:
        javax.jcr.RepositoryException - if an error occurs while accessing the repository