Example usage for com.liferay.portal.kernel.util Time getTimestamp

List of usage examples for com.liferay.portal.kernel.util Time getTimestamp

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Time getTimestamp.

Prototype

public static String getTimestamp() 

Source Link

Usage

From source file:com.liferay.exportimport.internal.background.task.LayoutExportBackgroundTaskExecutor.java

License:Open Source License

@Override
public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException {

    ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask);

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    long userId = MapUtil.getLong(settingsMap, "userId");

    StringBundler sb = new StringBundler(4);

    sb.append(StringUtil.replace(exportImportConfiguration.getName(), CharPool.SPACE, CharPool.UNDERLINE));
    sb.append(StringPool.DASH);/*  www.j  a v  a  2s . co m*/
    sb.append(Time.getTimestamp());
    sb.append(".lar");

    File larFile = ExportImportLocalServiceUtil.exportLayoutsAsFile(exportImportConfiguration);

    BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(),
            sb.toString(), larFile);

    return BackgroundTaskResult.SUCCESS;
}

From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java

License:Open Source License

@Override
public ZipWriter getLayoutSetZipWriter(long groupId) {
    StringBundler sb = new StringBundler(4);

    sb.append(groupId);//from www .  ja va 2s . c  om
    sb.append(StringPool.DASH);
    sb.append(Time.getTimestamp());
    sb.append(".lar");

    return getZipWriter(sb.toString());
}

From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java

License:Open Source License

@Override
public ZipWriter getPortletZipWriter(String portletId) {
    StringBundler sb = new StringBundler(4);

    sb.append(portletId);/*w  w w.j av a 2 s.  c  om*/
    sb.append(StringPool.DASH);
    sb.append(Time.getTimestamp());
    sb.append(".lar");

    return getZipWriter(sb.toString());
}

From source file:com.liferay.marketplace.service.impl.AppLocalServiceImpl.java

License:Open Source License

@Override
public void installApp(long remoteAppId) throws PortalException {
    App app = appPersistence.findByRemoteAppId(remoteAppId);

    if (!DLStoreUtil.hasFile(app.getCompanyId(), CompanyConstants.SYSTEM, app.getFilePath())) {

        throw new NoSuchFileException();
    }/*from w  ww. j a  v  a 2  s  .  c  o m*/

    String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR) + StringPool.SLASH + Time.getTimestamp();

    InputStream inputStream = null;

    ZipFile zipFile = null;

    try {
        inputStream = DLStoreUtil.getFileAsStream(app.getCompanyId(), CompanyConstants.SYSTEM,
                app.getFilePath());

        if (inputStream == null) {
            throw new IOException("Unable to open file at " + app.getFilePath());
        }

        File liferayPackageFile = FileUtil.createTempFile(inputStream);

        zipFile = new ZipFile(liferayPackageFile);

        Enumeration<ZipEntry> enu = (Enumeration<ZipEntry>) zipFile.entries();

        while (enu.hasMoreElements()) {
            ZipEntry zipEntry = enu.nextElement();

            String fileName = zipEntry.getName();

            if (!fileName.endsWith(".jar") && !fileName.endsWith(".war") && !fileName.endsWith(".xml")
                    && !fileName.endsWith(".zip") && !fileName.equals("liferay-marketplace.properties")) {

                continue;
            }

            if (_log.isInfoEnabled()) {
                _log.info("Extracting " + fileName + " from app " + app.getAppId());
            }

            InputStream zipInputStream = null;

            try {
                zipInputStream = zipFile.getInputStream(zipEntry);

                if (fileName.equals("liferay-marketplace.properties")) {
                    String propertiesString = StringUtil.read(zipInputStream);

                    Properties properties = PropertiesUtil.load(propertiesString);

                    processMarketplaceProperties(properties);
                } else {
                    File pluginPackageFile = new File(tmpDir + StringPool.SLASH + fileName);

                    FileUtil.write(pluginPackageFile, zipInputStream);

                    String bundleSymbolicName = StringPool.BLANK;
                    String bundleVersion = StringPool.BLANK;
                    String contextName = StringPool.BLANK;

                    AutoDeploymentContext autoDeploymentContext = new AutoDeploymentContext();

                    if (fileName.endsWith(".jar")) {
                        Manifest manifest = BundleUtil.getManifest(pluginPackageFile);

                        Attributes attributes = manifest.getMainAttributes();

                        bundleSymbolicName = GetterUtil.getString(attributes.getValue("Bundle-SymbolicName"));
                        bundleVersion = GetterUtil.getString(attributes.getValue("Bundle-Version"));
                        contextName = GetterUtil.getString(attributes.getValue("Web-ContextPath"));
                    } else {
                        contextName = getContextName(fileName);

                        autoDeploymentContext.setContext(contextName);
                    }

                    autoDeploymentContext.setFile(pluginPackageFile);

                    DeployManagerUtil.deploy(autoDeploymentContext);

                    if (Validator.isNotNull(bundleSymbolicName) || Validator.isNotNull(contextName)) {

                        moduleLocalService.addModule(app.getUserId(), app.getAppId(), bundleSymbolicName,
                                bundleVersion, contextName);
                    }
                }
            } finally {
                StreamUtil.cleanUp(zipInputStream);
            }
        }
    } catch (ZipException ze) {
        if (_log.isInfoEnabled()) {
            _log.info("Deleting corrupt package from app " + app.getAppId(), ze);
        }

        deleteApp(app);
    } catch (IOException ioe) {
        throw new PortalException(ioe.getMessage());
    } catch (Exception e) {
        _log.error(e, e);
    } finally {
        FileUtil.deltree(tmpDir);

        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException ioe) {
            }
        }

        StreamUtil.cleanUp(inputStream);

        clearInstalledAppsCache();
    }
}

From source file:com.liferay.testhook.util.TestHookUtil.java

License:Open Source License

private TestHookUtil() {
    String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);

    _startupActionFileName = tmpDir + "/liferay/testhook/" + Time.getTimestamp();
}

From source file:com.liferay.util.ant.Java2WsddTask.java

License:Open Source License

public static String[] generateWsdd(String className, String serviceName) throws Exception {

    // Create temp directory

    File tempDir = new File(Time.getTimestamp());

    tempDir.mkdir();/*from   ww  w  . j a v a 2  s .c  o  m*/

    // axis-java2wsdl

    String wsdlFileName = tempDir + "/service.wsdl";

    int pos = className.lastIndexOf(".");

    String packagePath = className.substring(0, pos);

    String[] packagePaths = StringUtil.split(packagePath, '.');

    String namespace = "urn:";

    for (int i = packagePaths.length - 1; i >= 0; i--) {
        namespace += packagePaths[i];

        if (i > 0) {
            namespace += ".";
        }
    }

    String location = "http://localhost/services/" + serviceName;

    String mappingPackage = packagePath.substring(0, packagePath.lastIndexOf(".")) + ".ws";

    Project project = AntUtil.getProject();

    Java2WsdlAntTask java2Wsdl = new Java2WsdlAntTask();

    NamespaceMapping mapping = new NamespaceMapping();

    mapping.setNamespace(namespace);
    mapping.setPackage(mappingPackage);

    java2Wsdl.setProject(project);
    java2Wsdl.setClassName(className);
    java2Wsdl.setOutput(new File(wsdlFileName));
    java2Wsdl.setLocation(location);
    java2Wsdl.setNamespace(namespace);
    java2Wsdl.addMapping(mapping);

    java2Wsdl.execute();

    // axis-wsdl2java

    Wsdl2javaAntTask wsdl2Java = new Wsdl2javaAntTask();

    wsdl2Java.setProject(project);
    wsdl2Java.setURL(wsdlFileName);
    wsdl2Java.setOutput(tempDir);
    wsdl2Java.setServerSide(true);
    wsdl2Java.setTestCase(false);
    wsdl2Java.setVerbose(false);

    wsdl2Java.execute();

    // Get content

    String deployContent = FileUtil
            .read(tempDir + "/" + StringUtil.replace(packagePath, ".", "/") + "/deploy.wsdd");

    deployContent = StringUtil.replace(deployContent, packagePath + "." + serviceName + "SoapBindingImpl",
            className);

    deployContent = _format(deployContent);

    String undeployContent = FileUtil
            .read(tempDir + "/" + StringUtil.replace(packagePath, ".", "/") + "/undeploy.wsdd");

    undeployContent = _format(undeployContent);

    // Delete temp directory

    DeleteTask.deleteDirectory(tempDir);

    return new String[] { deployContent, undeployContent };
}