Package com.liferay.resourcesimporter.util

Examples of com.liferay.resourcesimporter.util.Importer


      long companyId = CompanyThreadLocal.getCompanyId();

      try {
        CompanyThreadLocal.setCompanyId(company.getCompanyId());

        Importer importer = null;

        if ((privateLARURL != null) || (publicLARURL != null)) {
          LARImporter larImporter = getLARImporter();

          URLConnection privateLARURLConnection = null;

          if (privateLARURL != null) {
            privateLARURLConnection =
              privateLARURL.openConnection();

            larImporter.setPrivateLARInputStream(
              privateLARURLConnection.getInputStream());
          }

          URLConnection publicLARURLConnection = null;

          if (publicLARURL != null) {
            publicLARURLConnection = publicLARURL.openConnection();

            larImporter.setPublicLARInputStream(
              publicLARURLConnection.getInputStream());
          }

          importer = larImporter;
        }
        else if ((resourcePaths != null) && !resourcePaths.isEmpty()) {
          importer = getResourceImporter();

          importer.setResourcesDir(_RESOURCES_DIR);
        }
        else {
          String resourcesDir = pluginPackageProperties.getProperty(
            "resources-importer-external-dir");

          if (Validator.isNotNull(resourcesDir)) {
            importer = getFileSystemImporter();

            importer.setResourcesDir(resourcesDir);
          }
        }

        if (importer == null) {
          throw new ImporterException("No valid importer found");
        }

        importer.setCompanyId(company.getCompanyId());
        importer.setServletContext(servletContext);
        importer.setServletContextName(servletContextName);
        importer.setTargetClassName(targetClassName);

        String targetValue = pluginPackageProperties.getProperty(
          "resources-importer-target-value");

        if (Validator.isNull(targetValue)) {
          targetValue = TextFormatter.format(
            servletContextName, TextFormatter.J);
        }

        importer.setTargetValue(targetValue);

        importer.afterPropertiesSet();

        boolean developerModeEnabled = GetterUtil.getBoolean(
          pluginPackageProperties.getProperty(
            "resources-importer-developer-mode-enabled"));

        if (!developerModeEnabled && importer.isExisting()) {
          if (_log.isInfoEnabled()) {
            _log.info(
              "Group or layout set prototype already exists " +
                "for company " + company.getWebId());
          }

          continue;
        }

        long startTime = 0;

        if (_log.isInfoEnabled()) {
          startTime = System.currentTimeMillis();
        }

        importer.importResources();

        if (_log.isInfoEnabled()) {
          long endTime = System.currentTimeMillis() - startTime;

          _log.info(
            "Importing resources from " + servletContextName +
              " to group " + importer.getGroupId() + " takes " +
                endTime + " ms");
        }

        Message newMessage = new Message();

        newMessage.put("companyId", company.getCompanyId());
        newMessage.put("servletContextName", servletContextName);
        newMessage.put("targetClassName", targetClassName);
        newMessage.put("targetClassPK", importer.getTargetClassPK());

        if (message.getResponseId() != null) {
          Map<String, Object> responseMap =
            new HashMap<String, Object>();

          responseMap.put("groupId", importer.getTargetClassPK());

          newMessage.setPayload(responseMap);

          newMessage.setResponseId(message.getResponseId());
        }
View Full Code Here


      long companyId = CompanyThreadLocal.getCompanyId();

      try {
        CompanyThreadLocal.setCompanyId(company.getCompanyId());

        Importer importer = null;

        if ((privateLARURL != null) || (publicLARURL != null)) {
          LARImporter larImporter = getLARImporter();

          URLConnection privateLARURLConnection = null;

          if (privateLARURL != null) {
            privateLARURLConnection =
              privateLARURL.openConnection();

            larImporter.setPrivateLARInputStream(
              privateLARURLConnection.getInputStream());
          }

          URLConnection publicLARURLConnection = null;

          if (publicLARURL != null) {
            publicLARURLConnection = publicLARURL.openConnection();

            larImporter.setPublicLARInputStream(
              publicLARURLConnection.getInputStream());
          }

          importer = larImporter;
        }
        else if ((resourcePaths != null) && !resourcePaths.isEmpty()) {
          importer = getResourceImporter();

          importer.setResourcesDir(_RESOURCES_DIR);
        }
        else if ((templatePaths != null) && !templatePaths.isEmpty()) {
          importer = getResourceImporter();

          Group group = GroupLocalServiceUtil.getCompanyGroup(
            company.getCompanyId());

          importer.setGroupId(group.getGroupId());
          importer.setResourcesDir(_TEMPLATES_DIR);
        }
        else {
          String resourcesDir = pluginPackageProperties.getProperty(
            "resources-importer-external-dir");

          if (Validator.isNotNull(resourcesDir)) {
            importer = getFileSystemImporter();

            importer.setResourcesDir(resourcesDir);
          }
        }

        if (importer == null) {
          throw new ImporterException("No valid importer found");
        }

        importer.setCompanyId(company.getCompanyId());
        importer.setServletContext(servletContext);
        importer.setServletContextName(servletContextName);
        importer.setTargetClassName(targetClassName);

        String targetValue = pluginPackageProperties.getProperty(
          "resources-importer-target-value");

        if (Validator.isNull(targetValue)) {
          targetValue = TextFormatter.format(
            servletContextName, TextFormatter.J);
        }

        importer.setTargetValue(targetValue);

        PluginPackage pluginPackage =
          DeployManagerUtil.getInstalledPluginPackage(
            servletContextName);

        importer.setVersion(pluginPackage.getVersion());

        boolean developerModeEnabled = GetterUtil.getBoolean(
          pluginPackageProperties.getProperty(
            "resources-importer-developer-mode-enabled"));

        importer.setDeveloperModeEnabled(developerModeEnabled);

        importer.afterPropertiesSet();

        if (!developerModeEnabled && importer.isExisting() &&
          !importer.isCompanyGroup()) {

          if (_log.isInfoEnabled()) {
            _log.info(
              "Group or layout set prototype already exists " +
                "for company " + company.getWebId());
          }

          continue;
        }

        long startTime = 0;

        if (_log.isInfoEnabled()) {
          startTime = System.currentTimeMillis();
        }

        importer.importResources();

        if (_log.isInfoEnabled()) {
          long endTime = System.currentTimeMillis() - startTime;

          _log.info(
            "Importing resources from " + servletContextName +
              " to group " + importer.getGroupId() + " takes " +
                endTime + " ms");
        }

        Message newMessage = new Message();

        newMessage.put("companyId", company.getCompanyId());
        newMessage.put("servletContextName", servletContextName);
        newMessage.put("targetClassName", targetClassName);
        newMessage.put("targetClassPK", importer.getTargetClassPK());

        if (message.getResponseId() != null) {
          Map<String, Object> responseMap =
            new HashMap<String, Object>();

          responseMap.put("groupId", importer.getTargetClassPK());

          newMessage.setPayload(responseMap);

          newMessage.setResponseId(message.getResponseId());
        }
View Full Code Here

TOP

Related Classes of com.liferay.resourcesimporter.util.Importer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.