| package com.abg.loyaltyservice.util;
|
|
|
| import java.util.ArrayList;
|
| import java.util.Arrays;
|
| import java.util.HashMap;
|
| import java.util.List;
|
| import java.util.Map;
|
| import java.util.Properties;
|
|
|
| import javax.jcr.Node;
|
| import javax.jcr.NodeIterator;
|
| import javax.jcr.PathNotFoundException;
|
| import javax.jcr.Property;
|
| import javax.jcr.RepositoryException;
|
| import javax.jcr.Session;
|
| import javax.jcr.ValueFormatException;
|
|
|
| import org.apache.commons.lang3.StringUtils;
|
| import org.apache.logging.log4j.LogManager;
|
| import org.apache.logging.log4j.Logger;
|
|
|
| import com.abg.loyaltyservice.constant.ABGConstants;
|
| import com.abg.loyaltyservice.constant.CMAConstants;
|
| import com.abg.loyaltyservice.entities.ContactApp;
|
| import com.abg.loyaltyservice.exception.CMSException;
|
|
|
| import info.magnolia.cms.core.MgnlNodeType;
|
| import info.magnolia.context.MgnlContext;
|
| import info.magnolia.jcr.util.NodeTypes;
|
| import info.magnolia.jcr.util.NodeUtil;
|
| import info.magnolia.jcr.util.PropertyUtil;
|
|
|
| /**
|
| * CMSContentReader - This utility class provides an abstract way to get the
|
| * data from CMS without knowing the session values.
|
| *
|
| */
|
|
|
| @SuppressWarnings("deprecation")
|
| public final class CMSContentReader {
|
|
|
| private static final Logger LOGGER = LogManager.getLogger(CMSContentReader.class);
|
|
|
| private transient Session session;
|
|
|
| private transient Node node;
|
|
|
| /**
|
| * Default Constructor - creates a session for data workspace.
|
| *
|
| * @throws Exception throws Exception if the operations fails
|
| */
|
| public CMSContentReader() throws CMSException {
|
| session = getSession(null);
|
| }
|
|
|
| /**
|
| * Creates session based on the given workspace.
|
| *
|
| * @param workspace the path to workspace
|
| * @throws Exception throws CGAutoException if the operations fails
|
| */
|
| public CMSContentReader(final String workspace) throws CMSException {
|
| session = getSession(workspace);
|
| }
|
|
|
| /**
|
| *
|
| * @param workspace path of workspace
|
| * @return session object
|
| * @throws Exception throws CGAutoException if the operations fails
|
| */
|
| private Session getSession(final String workspace) throws CMSException {
|
| Session cmsSession;
|
| try {
|
| cmsSession = MgnlContext.getJCRSession(workspace);
|
| } catch (Exception e) {
|
| LOGGER.error("CMSContentReader :: getSession --> Exception " + e.getMessage());
|
| throw new CMSException("CMSContentReader:getSession --> Exception", e);
|
| }
|
| return cmsSession;
|
| }
|
|
|
| /**
|
| * Returns the current session
|
| *
|
| * @return
|
| */
|
| public Session getSession() {
|
| return session;
|
| }
|
|
|
| /**
|
| * Fetches the node for the specifide path. Use this method if the path
|
| * specified is known to have only one node under it
|
| *
|
| * @param path - The path under which the node is required.
|
| * @return Node - the node under the specified path
|
| * @throws Exception throws Exception if the operations fails
|
| */
|
| public Node getNode(final String path) throws CMSException {
|
| Node currentNode = null;
|
| try {
|
| if (session.nodeExists(path)) {
|
| currentNode = session.getNode(path);
|
| }
|
| } catch (PathNotFoundException e) {
|
| LOGGER.error("CMSContentReader::getNode--> PathNotFoundException " + e.getMessage());
|
| throw new CMSException("CMSContentReader : getNode --> PathNotFoundException ", e);
|
| } catch (RepositoryException e) {
|
| LOGGER.error("CMSContentReader::getNode --> RepositoryException " + e.getMessage());
|
| throw new CMSException("CMSContentReader : getNode --> RepositoryException ", e);
|
| }
|
| return currentNode;
|
| }
|
|
|
| /**
|
| * Fetches the node for the specifide path. Use this method if the path
|
| * specified is known to have only one node under it
|
| *
|
| * @param path - The path under which the node is required.
|
| * @return Node - the node under the specified path
|
| * @throws Exception throws Exception if the operations fails
|
| */
|
| public boolean checkNodeExist(final String path) throws CMSException {
|
| boolean nodeExistsflag = false;
|
| try {
|
| if (session.nodeExists(path)) {
|
| nodeExistsflag = true;
|
| }
|
| } catch (PathNotFoundException e) {
|
| LOGGER.error("CMSContentReader :: checkNodeExist --> PathNotFoundException " + e.getMessage());
|
| throw new CMSException("CMSContentReader:checkNodeExist --> PathNotFoundException ", e);
|
| } catch (RepositoryException e) {
|
| LOGGER.error("CMSContentReader :: checkNodeExist --> RepositoryException " + e.getMessage());
|
| throw new CMSException("CMSContentReader:checkNodeExist --> RepositoryException ", e);
|
| }
|
| return nodeExistsflag;
|
| }
|
|
|
| /**
|
| * Fetches the node for the specific path. Use this method if the path specified
|
| * is known to have only one node under it
|
| *
|
| * @param path - The path under which the node is required.
|
| * @return Node - the node under the specified path DOES NOT THROW EXCEPTION
|
| * @throws CMSException
|
| */
|
| public boolean checkNodeExistWithoutException(final String path) throws CMSException {
|
| boolean nodeExistsflag = false;
|
| try {
|
| if (session.nodeExists(path)) {
|
| nodeExistsflag = true;
|
| }
|
| } catch (PathNotFoundException e) {
|
| LOGGER.error(
|
| "CMSContentReader :: checkNodeExistWithoutException --> PathNotFoundException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::PathNotFoundException ::getSubNodesIterator --> ", e);
|
| } catch (RepositoryException e) {
|
| LOGGER.error(
|
| "CMSContentReader :: checkNodeExistWithoutException --> RepositoryException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::getSubNodesIterator --> RepositoryException ", e);
|
| }
|
| return nodeExistsflag;
|
| }
|
|
|
| /**
|
| *
|
| * @param path
|
| * @return
|
| * @throws CMSException
|
| */
|
| public NodeIterator getSubNodesIterator(final String path) throws CMSException {
|
|
|
| NodeIterator ite = null;
|
| try {
|
| if (session.nodeExists(path)) {
|
| ite = session.getNode(path).getNodes();
|
| }
|
| } catch (PathNotFoundException e) {
|
| LOGGER.error("CMSContentReader :: getSubNodesIterator --> PathNotFoundException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::getSubNodesIterator --> PathNotFoundException ", e);
|
| } catch (RepositoryException e) {
|
| LOGGER.error("CMSContentReader :: getSubNodesIterator --> RepositoryException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::--> RepositoryException ::getSubNodesIterator ", e);
|
| }
|
| return ite;
|
| }
|
|
|
| /**
|
| * Gets the property value under a specified node.
|
| *
|
| * @param node the node under which the property is to be searched
|
| * @param propertyToFetch the property to be fetched under the given node
|
| * @return String the value of the property.
|
| * @throws CGAutoException throws CGAutoException if the operations fails
|
| */
|
| public String getNodeProperty(final Node node, final String propertyToFetch) throws CMSException {
|
| String retString = StringUtils.EMPTY;
|
| try {
|
| if (null != node && node.hasProperty(propertyToFetch)) {
|
| retString = node.getProperty(propertyToFetch).getString();
|
| }
|
| } catch (ValueFormatException e) {
|
| LOGGER.error("CMSContentReader :: getNodeProperty --> ValueFormatException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::getNodeProperty --> ValueFormatException ", e);
|
| } catch (PathNotFoundException e) {
|
| LOGGER.error("CMSContentReader :: getNodeProperty --> PathNotFoundException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::getNodeProperty --> PathNotFoundException ", e);
|
| } catch (RepositoryException e) {
|
| LOGGER.error("CMSContentReader :: getNodeProperty --> RepositoryException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::getNodeProperty --> RepositoryException ", e);
|
| }
|
| return retString;
|
| }
|
|
|
| public boolean isMetadata(final String nodeName) {
|
| return nodeName.contains(CMAConstants.JCR) || nodeName.contains(CMAConstants.METADATA);
|
| }
|
|
|
| /*
|
| * Gets the all property value under a specified node.
|
| *
|
| * @param node under which the property is to be searched
|
| *
|
| * @return all properties value in Properties object
|
| *
|
| * @throws CMSException
|
| */
|
| public Properties getAllPropertyFromNode(final Node node) throws CMSException {
|
| Properties nodeProperties = new Properties();
|
| try {
|
| NodeIterator nodes = node.getNodes();
|
| while (nodes.hasNext()) {
|
| String nodeValue = StringUtils.EMPTY;
|
| String nodeKey = StringUtils.EMPTY;
|
| Node nextNode = nodes.nextNode();
|
| if (nextNode.hasProperty(CMAConstants.JCR_VALUE)) {
|
| Property property = nextNode.getProperty(CMAConstants.JCR_VALUE);
|
| if (null != property && null != property.getValue()) {
|
| nodeValue = property.getValue().getString();
|
| }
|
| nodeKey = nextNode.getName().toString();
|
| nodeProperties.setProperty(nodeKey, nodeValue);
|
| } else {
|
| nodeKey = nextNode.getName().toString();
|
| nodeProperties.setProperty(nodeKey, StringUtils.EMPTY);
|
| }
|
| }
|
| } catch (ValueFormatException e) {
|
| LOGGER.error("CMSContentReader :: getAllPropertyFromNode --> ValueFormatException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::getAllPropertyFromNode --> ValueFormatException ", e);
|
| } catch (PathNotFoundException e) {
|
| LOGGER.error("CMSContentReader :: getAllPropertyFromNode --> PathNotFoundException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::getAllPropertyFromNode --> PathNotFoundException ", e);
|
| } catch (RepositoryException e) {
|
| LOGGER.error("CMSContentReader :: getAllPropertyFromNode --> RepositoryException " + e.getMessage());
|
| throw new CMSException("CMSContentReader::getNodeProperty --> RepositoryException ", e);
|
| }
|
| return nodeProperties;
|
| }
|
|
|
| public void createNodeIfDoesNotExist(final String[] pathUrl) throws CMSException, RepositoryException {
|
| for (String path : pathUrl) {
|
| boolean nodeExistsflag = checkNodeExistWithoutException(path);
|
| if (!nodeExistsflag) {
|
| Node root = session.getRootNode();
|
| root.addNode(path.replaceAll(ABGConstants.FORWARD_SLASH, StringUtils.EMPTY), MgnlNodeType.NT_FOLDER);
|
| session.save();
|
| }
|
| }
|
| }
|
|
|
| /**
|
| * @param path
|
| * @return
|
| * @throws RepositoryException
|
| */
|
| public ContactApp loadContacts(String path) throws RepositoryException {
|
| ContactApp contactApp = new ContactApp();
|
| Node contactsNode = session.getNode(path);
|
| NodeIterator nodeIterator = contactsNode.getNodes();
|
| while (nodeIterator.hasNext()) {
|
| Node nodeContact = nodeIterator.nextNode();
|
| String nodeName = nodeContact.getName();
|
| if (nodeName.equals(ABGConstants.RESERVATION_MGMT_NODE)
|
| && nodeContact.hasProperty(ABGConstants.OFFICE_PHONE_KEY)) {
|
| contactApp.setReservationPhone(
|
| nodeContact.getProperty(ABGConstants.OFFICE_PHONE_KEY).getValue().getString());
|
| }
|
| if (nodeName.equals(ABGConstants.CUSTOMER_SERV_NODE)) {
|
| if (nodeContact.hasProperty(ABGConstants.OFFICE_PHONE_KEY)) {
|
| contactApp.setCustomerPhone(
|
| nodeContact.getProperty(ABGConstants.OFFICE_PHONE_KEY).getValue().getString());
|
| }
|
| if (nodeContact.hasProperty(ABGConstants.OFFICE_FAX_KEY)) {
|
| contactApp.setOperatingHours(
|
| nodeContact.getProperty(ABGConstants.OFFICE_FAX_KEY).getValue().getString());
|
| }
|
| if (nodeContact.hasProperty(ABGConstants.CONTACT_EMAIL_KEY)) {
|
| contactApp.setCustomerEmail(
|
| nodeContact.getProperty(ABGConstants.CONTACT_EMAIL_KEY).getValue().getString());
|
| }
|
| }
|
| if (nodeName.equals(ABGConstants.SOCIAL_MEDIA_NODE)
|
| && !PropertyUtil.getString(nodeContact, ABGConstants.WEBSITE_KEY, Boolean.FALSE.toString())
|
| .equals(Boolean.FALSE.toString())) {
|
| String[] socialMediaUrl = nodeContact.getProperty(ABGConstants.WEBSITE_KEY).getValue().getString()
|
| .split(",");
|
| Arrays.stream(socialMediaUrl).forEach(sm -> {
|
| if (sm.contains(ABGConstants.FB_PREFIX + ABGConstants.HYPHEN))
|
| contactApp.setFacebookUrl(
|
| sm.replaceFirst(ABGConstants.FB_PREFIX + ABGConstants.HYPHEN, StringUtils.EMPTY));
|
| else if (sm.contains(ABGConstants.YT_PREFIX + ABGConstants.HYPHEN))
|
| contactApp.setYoutubeUrl(
|
| sm.replaceFirst(ABGConstants.YT_PREFIX + ABGConstants.HYPHEN, StringUtils.EMPTY));
|
| else if (sm.contains(ABGConstants.IT_PREFIX + ABGConstants.HYPHEN))
|
| contactApp.setInstagramUrl(
|
| sm.replaceFirst(ABGConstants.IT_PREFIX + ABGConstants.HYPHEN, StringUtils.EMPTY));
|
| else if (sm.contains(ABGConstants.TW_PREFIX + ABGConstants.HYPHEN))
|
| contactApp.setTwitterUrl(
|
| sm.replaceFirst(ABGConstants.TW_PREFIX + ABGConstants.HYPHEN, StringUtils.EMPTY));
|
| });
|
| }
|
| }
|
| return contactApp;
|
| }
|
|
|
| /**
|
| * Duplicate node from avis-Licensee with avis-Country
|
| *
|
| * @param srcPath
|
| * @param destPath
|
| * @throws RepositoryException
|
| */
|
| public void createDuplicateNode(final String srcPath, final String destPath) throws RepositoryException {
|
| Node srcNode = session.getNode(srcPath);
|
| NodeUtil.copyInSession(srcNode, destPath);
|
| session.save();
|
| }
|
|
|
| /**
|
| * Verify if given node path exist in workspace
|
| *
|
| * @param genericSession
|
| * @param path
|
| * @return
|
| */
|
| public boolean isPathNotExist(String path) {
|
| boolean flagPath = false;
|
| try {
|
| node = session.getNode(path);
|
| } catch (RepositoryException e) {
|
| LOGGER.info("CMSContentReader : isPathExist :: Requested path doest not exist - " + e.getMessage());
|
| flagPath = true;
|
| }
|
| return flagPath;
|
| }
|
|
|
| /**
|
| * Return List of child nodes from given workspace.
|
| *
|
| * @param path
|
| * @return
|
| * @throws RepositoryException
|
| */
|
| public List<Node> getAllChildNodes(String path) throws RepositoryException {
|
| List<Node> aclNodeLst = new ArrayList<>();
|
| if (!isPathNotExist(path)) {
|
| NodeIterator nodeIterator = node.getNodes();
|
| while (nodeIterator.hasNext()) {
|
| Node currentNode = nodeIterator.nextNode();
|
| aclNodeLst.add(currentNode);
|
| }
|
| }
|
| return aclNodeLst;
|
| }
|
|
|
| /**
|
| * Return List of child nodes name from given workspace.
|
| *
|
| * @param path
|
| * @return
|
| * @throws RepositoryException
|
| */
|
| public List<String> getAllChildNodesName(String path) throws RepositoryException {
|
| List<String> aclNodeLst = new ArrayList<>();
|
| if (!isPathNotExist(path)) {
|
| NodeIterator nodeIterator = node.getNodes();
|
| while (nodeIterator.hasNext()) {
|
| Node currentNode = nodeIterator.nextNode();
|
| aclNodeLst.add(currentNode.getName());
|
| }
|
| }
|
| return aclNodeLst;
|
| }
|
|
|
| /**
|
| * This method is used to update the property value.
|
| *
|
| * @param path
|
| * @param name
|
| * @param value
|
| * @throws RepositoryException
|
| */
|
| public void updateProperty(String path, String name, String value) throws RepositoryException {
|
| if (!isPathNotExist(path)) {
|
| node.setProperty(name, value);
|
| session.save();
|
| }
|
| }
|
|
|
| /**
|
| * @param path
|
| * @param srcProp
|
| * @param destProp
|
| * @throws RepositoryException
|
| */
|
| public void updateAllProperty(String path, String srcProp, String destProp) throws RepositoryException {
|
| List<Node> aclNodes = getAllChildNodes(path);
|
| for (Node aclNode : aclNodes) {
|
| NodeIterator nodeIterator = aclNode.getNodes();
|
| while (nodeIterator.hasNext()) {
|
| Node currentNode = nodeIterator.nextNode();
|
| String propValue = currentNode.getProperty(ABGConstants.PATH).getValue().getString();
|
| if (propValue.contains(srcProp)) {
|
| propValue = currentNode.getPath().contains(ABGConstants.ACL_DAM)
|
| ? propValue.replaceAll(ABGConstants.FORWARD_SLASH + srcProp,
|
| ABGConstants.FORWARD_SLASH + destProp.toLowerCase())
|
| : propValue.replaceAll(ABGConstants.FORWARD_SLASH + srcProp,
|
| ABGConstants.FORWARD_SLASH + destProp);
|
| currentNode.setProperty(ABGConstants.PATH, propValue);
|
| LOGGER.info("CMSContenetReader :: updateNestedProperty :: Node : " + currentNode.getName()
|
| + " :: updated value :: {}", propValue);
|
| }
|
| }
|
| }
|
| session.save();
|
| }
|
|
|
| /**
|
| * @param path
|
| * @param propMap
|
| * @throws RepositoryException
|
| */
|
| public void updateContactProperty(String path, Map<String, String> propMap) throws RepositoryException {
|
| List<Node> aclNodes = getAllChildNodes(path);
|
| for (Node currentNode : aclNodes) {
|
| String nodeName = currentNode.getName();
|
| currentNode.setProperty(ABGConstants.ORGANIZATION_NAME_KEY,
|
| propMap.get(ABGConstants.ORGANIZATION_NAME_KEY));
|
| currentNode.setProperty(ABGConstants.CONTACT_EMAIL_KEY, propMap.get(ABGConstants.CONTACT_EMAIL_KEY));
|
| if (nodeName.equals(ABGConstants.RESERVATION_MGMT_NODE)) {
|
| currentNode.setProperty(ABGConstants.OFFICE_PHONE_KEY, propMap.get(ABGConstants.RESERVATION_PHONE_KEY));
|
| if (!StringUtils.isEmpty(propMap.get(ABGConstants.RESERVATION_OFFICE_FAX_KEY))) {
|
| currentNode.setProperty(ABGConstants.OFFICE_FAX_KEY,
|
| propMap.get(ABGConstants.RESERVATION_OFFICE_FAX_KEY));
|
| }
|
| }
|
| if (nodeName.equals(ABGConstants.CUSTOMER_SERV_NODE)) {
|
| currentNode.setProperty(ABGConstants.OFFICE_PHONE_KEY, propMap.get(ABGConstants.CUSTOMER_PHONE_KEY));
|
| currentNode.setProperty(ABGConstants.OFFICE_FAX_KEY, propMap.get(ABGConstants.OFFICE_FAX_KEY));
|
| }
|
| if (nodeName.equals(ABGConstants.SOCIAL_MEDIA_NODE)
|
| && !StringUtils.isBlank(propMap.get(ABGConstants.WEBSITE_KEY))) {
|
| currentNode.setProperty(ABGConstants.WEBSITE_KEY, propMap.get(ABGConstants.WEBSITE_KEY));
|
| }
|
| if (nodeName.equals(ABGConstants.PRESTIGE_NODE)
|
| && !StringUtils.isBlank(propMap.get(ABGConstants.PRESTIGE_PHONE))) {
|
| currentNode.setProperty(ABGConstants.OFFICE_PHONE_KEY, propMap.get(ABGConstants.PRESTIGE_PHONE));
|
| }
|
| }
|
| session.save();
|
| }
|
|
|
| /**
|
| * Return List of all languages from given country.
|
| *
|
| * @param path
|
| * @return
|
| * @throws RepositoryException
|
| */
|
| public String getPrimaryLanguage(String path) throws RepositoryException {
|
| String lang = StringUtils.EMPTY;
|
| if (!isPathNotExist(path)) {
|
| String locale = node.getNode(ABGConstants.I18_PATH).getProperty(ABGConstants.DEFAULT_LOCALE).getString();
|
| try {
|
| Node currentNode = getNode(StringUtils.substringBefore(path, ABGConstants.HYPHEN) + ABGConstants.HYPHEN
|
| + "Licensees" + ABGConstants.FORWARD_SLASH + ABGConstants.LOCALESITEDEFINITION
|
| + ABGConstants.FORWARD_SLASH + locale);
|
| if (currentNode != null && currentNode.hasProperty(ABGConstants.LANGUAGE_NAME)) {
|
| lang = currentNode.getProperty(ABGConstants.LANGUAGE_NAME).getString();
|
| }
|
|
|
| } catch (CMSException e) {
|
| LOGGER.info(
|
| "CMSContentReader : getPrimaryLanguage :: Requested path doest not exist - " + e.getMessage());
|
| }
|
| }
|
| return lang;
|
| }
|
|
|
| /**
|
| * This method is used to create the parent/root page/node for a website, in
|
| * order to do this areas and components will be taken from the avis-Licensee
|
| * website.
|
| *
|
| * @param srcPath
|
| * @param destPath
|
| * @param locale
|
| * @param brand
|
| * @throws RepositoryException
|
| */
|
| public void createLicenceePage(final String srcPath, final String destPath, String locale, String brand)
|
| throws RepositoryException {
|
| // Create new node and add all property from avis-Licencee
|
| List<String> list = new ArrayList<>();
|
| Node rootNode = session.getNode(ABGConstants.FORWARD_SLASH);
|
| if (isPathNotExist(destPath)) {
|
| Node cntryNode = rootNode.addNode(StringUtils.removeStart(destPath, ABGConstants.FORWARD_SLASH),
|
| NodeTypes.Page.NAME);
|
| cntryNode.setProperty(ABGConstants.PAGE_LOCKMAIN_PROP_KEY, ABGConstants.FALSE);
|
| if (brand.equals(ABGConstants.AVIS_FOLDER)) {
|
| cntryNode.setProperty(NodeTypes.Renderable.TEMPLATE, ABGConstants.AVIS_HOME_TEMPLATE);
|
| cntryNode.setProperty(ABGConstants.PAGE_LOCK_PROP_KEY, ABGConstants.FALSE);
|
|
|
| cntryNode.setProperty(ABGConstants.USER.TITLE.toString(), ABGConstants.PAGE_TITLE);
|
| list.add("main");
|
| list.add("header");
|
| list.add("content");
|
| list.add("footer");
|
| }
|
| }
|
| session.save();
|
| list.add(locale);
|
| for (String nodeName : list) {
|
| copyNode(srcPath, destPath, nodeName);
|
| }
|
| }
|
|
|
| /**
|
| * This method is used to create the site definition for the new website.
|
| *
|
| * @param srcPath
|
| * @param destPath
|
| * @param locale
|
| * @param websiteNode
|
| * @param brand
|
| * @param isPrimaryLanguage
|
| * @param language
|
| * @throws RepositoryException
|
| */
|
| public void createLicenceeSiteDefnNode(String srcPath, final String destPath, String locale, String websiteNode,
|
| String brand, boolean isPrimaryLanguage, String language) throws RepositoryException {
|
| Node rootNode = session.getNode(srcPath).getParent();
|
| if (isPathNotExist(rootNode.getPath() + destPath)) {
|
| // Create new node and add all property from avis-Licencee
|
| Node cntryNode = rootNode.addNode(StringUtils.removeStart(destPath, ABGConstants.FORWARD_SLASH),
|
| NodeTypes.ContentNode.NAME);
|
| cntryNode.setProperty("extends", "../" + brand);
|
| session.save();
|
|
|
| // Create mapping Node and add website according to language
|
| cntryNode.addNode("mappings", NodeTypes.ContentNode.NAME);
|
| session.save();
|
|
|
| // Create i18NNode Node and add locales according to language
|
| Node i18NNode = cntryNode.addNode("i18n", NodeTypes.ContentNode.NAME);
|
| i18NNode.setProperty("class", ABGConstants.BUDGET_I18_CLASS);
|
| if (brand.equals(ABGConstants.AVIS_FOLDER)) {
|
| i18NNode.setProperty("class", ABGConstants.AVIS_I18_CLASS);
|
| }
|
| if (brand.equals(ABGConstants.BUDGET_FOLDER)) {
|
| i18NNode.setProperty("enabled", "false");
|
| } else {
|
| i18NNode.setProperty("enabled", "true");
|
| }
|
| session.save();
|
| i18NNode.addNode("locales", NodeTypes.ContentNode.NAME);
|
| session.save();
|
|
|
| List<String> list = new ArrayList<>();
|
| list.add("domains");
|
| list.add("configuration");
|
| list.add("parameters");
|
| for (String nodeName : list) {
|
| copyNode(srcPath, rootNode.getPath() + destPath, nodeName);
|
| }
|
| }
|
|
|
| copyNode(srcPath + ABGConstants.FORWARD_SLASH + ABGConstants.MAPPINGS,
|
| rootNode.getPath() + destPath + ABGConstants.FORWARD_SLASH + ABGConstants.MAPPINGS, websiteNode);
|
| if (brand.equals(ABGConstants.BUDGET_FOLDER) && isPrimaryLanguage) {
|
| NodeUtil.renameNode(
|
| session.getNode(rootNode.getPath() + destPath + ABGConstants.FORWARD_SLASH + ABGConstants.MAPPINGS
|
| + ABGConstants.SLASH + websiteNode),
|
| websiteNode.replaceAll(ABGConstants.UNDERSCORE + language, ""));
|
| websiteNode = websiteNode.replaceAll(ABGConstants.UNDERSCORE + language, "");
|
| session.save();
|
| }
|
| if (brand.equals(ABGConstants.BUDGET_FOLDER)) {
|
| copyNode(srcPath + ABGConstants.FORWARD_SLASH + ABGConstants.LOCALESITEDEFINITION,
|
| rootNode.getPath() + destPath + ABGConstants.LOCALE_PATH, locale);
|
| Node localeName = session
|
| .getNode(rootNode.getPath() + destPath + ABGConstants.LOCALE_PATH + ABGConstants.SLASH + locale);
|
| Property languageProp = localeName.getProperty("languageName");
|
| languageProp.remove();
|
| session.save();
|
| NodeUtil.renameNode(localeName, language);
|
| session.save();
|
| } else {
|
| copyNode(srcPath + ABGConstants.FORWARD_SLASH + ABGConstants.LOCALESITEDEFINITION,
|
| rootNode.getPath() + destPath + ABGConstants.LOCALE_PATH, locale);
|
| session.save();
|
| }
|
| session.getNode(rootNode.getPath() + destPath + ABGConstants.FORWARD_SLASH + ABGConstants.MAPPINGS
|
| + ABGConstants.FORWARD_SLASH + websiteNode)
|
| .setProperty(ABGConstants.HANDLE_PREFIX, destPath + ABGConstants.FORWARD_SLASH + locale);
|
|
|
| if (isPrimaryLanguage) {
|
| session.getNode(rootNode.getPath() + destPath + ABGConstants.FORWARD_SLASH + ABGConstants.I18_PATH)
|
| .setProperty(ABGConstants.DEFAULT_LOCALE, locale);
|
| session.getNode(rootNode.getPath() + destPath + ABGConstants.FORWARD_SLASH + ABGConstants.MAPPINGS
|
| + ABGConstants.FORWARD_SLASH + websiteNode)
|
| .setProperty(ABGConstants.URI_PREFIX, ABGConstants.FORWARD_SLASH);
|
| } else {
|
| session.getNode(rootNode.getPath() + destPath + ABGConstants.FORWARD_SLASH + ABGConstants.MAPPINGS
|
| + ABGConstants.FORWARD_SLASH + websiteNode)
|
| .setProperty(ABGConstants.URI_PREFIX, ABGConstants.FORWARD_SLASH + language);
|
| }
|
|
|
| }
|
|
|
| /**
|
| * This method is used to create the config labels for the new website.
|
| *
|
| * @param srcPath
|
| * @param srcPath
|
| * @param destPath
|
| * @param lang
|
| * @throws RepositoryException
|
| */
|
| public void createConfigNode(final String srcPath, final String destPath, String lang) throws RepositoryException {
|
| Node rootNode = session.getNode(srcPath).getParent();
|
| Node cntryNode = isPathNotExist(rootNode.getPath() + ABGConstants.FORWARD_SLASH + destPath)
|
| ? rootNode.addNode(destPath, NodeTypes.Folder.NAME)
|
| : rootNode.getNode(destPath);
|
| session.save();
|
| copyNode(srcPath, cntryNode.getPath(), lang);
|
| }
|
|
|
| /**
|
| * This method is used to copy a node from one node to other node, which doesn't
|
| * have the same parent.
|
| *
|
| * @param srcPath
|
| * @param destPath
|
| * @param nodeName
|
| * @throws RepositoryException
|
| */
|
| public void copyNode(String srcPath, final String destPath, String nodeName) throws RepositoryException {
|
| if (session.getNode(srcPath).hasNode(nodeName)) {
|
| try {
|
| String tempNode = srcPath + ABGConstants.FORWARD_SLASH + ABGConstants.TEMP_NODE;
|
| if (!checkNodeExist(tempNode)) {
|
| Node srcNode = session.getNode(srcPath + ABGConstants.FORWARD_SLASH + nodeName);
|
| NodeUtil.copyInSession(srcNode, tempNode);
|
| session.save();
|
| Node nodeToMove = session.getNode(tempNode);
|
| Node target = session.getNode(destPath);
|
| NodeUtil.moveNode(nodeToMove, target);
|
| session.save();
|
| Node renameNode = session.getNode(destPath + ABGConstants.FORWARD_SLASH + ABGConstants.TEMP_NODE);
|
| NodeUtil.renameNode(renameNode, nodeName);
|
| session.save();
|
| }
|
| } catch (CMSException ce) {
|
| LOGGER.info("CMSContentReader : copyNode :: Requested path doest not exist - " + ce.getMessage());
|
| }
|
| }
|
| }
|
|
|
| public Properties getUrldetails(String urlDetailsPath) throws RepositoryException, CMSException {
|
| return getAllPropertyFromNode(session.getNode(urlDetailsPath));
|
| }
|
|
|
| public void deleteNode(String srcPath) throws RepositoryException {
|
| session.getNode(srcPath).remove();
|
| session.save();
|
| }
|
|
|
| public Map<String, ContactApp> loadAllContactsByCountry(String brand) throws RepositoryException {
|
| Map<String, ContactApp> contactMaps = new HashMap<>();
|
| populateContacts(brand, contactMaps, ABGConstants.AVIS_LIGHT);
|
| populateContacts(brand, contactMaps, ABGConstants.WAVE3_CONTACT_NODE);
|
| return contactMaps;
|
| }
|
|
|
| /**
|
| * @param brand
|
| * @param contactMaps
|
| * @throws RepositoryException
|
| */
|
| public void populateContacts(String brand, Map<String, ContactApp> contactMaps, String contactRoot)
|
| throws RepositoryException {
|
| String wave3ContactsRootPath = ABGConstants.FORWARD_SLASH + contactRoot + ABGConstants.FORWARD_SLASH + brand;
|
| List<Node> wave3NodeList = getAllChildNodes(wave3ContactsRootPath);
|
| for (Node node : wave3NodeList) {
|
| String countryName = node.getName().contains(ABGConstants.UNDERSCORE)
|
| ? StringUtils.substringAfter(node.getName(), ABGConstants.UNDERSCORE)
|
| : StringUtils.substringAfter(node.getName(), ABGConstants.HYPHEN);
|
| if (getAllChildNodesName(node.getPath()).contains(ABGConstants.ENGLISH)) {
|
| contactMaps.put(countryName,
|
| loadContacts(node.getPath() + ABGConstants.FORWARD_SLASH + ABGConstants.ENGLISH));
|
| }
|
| }
|
| }
|
|
|
| }
|