Skip to content

Commit

Permalink
LPS-30463 Add developer mode
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnlok authored and brianchandotcom committed Oct 15, 2012
1 parent 811c07a commit e8fe898
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 47 deletions.
Expand Up @@ -8,4 +8,7 @@ change-log=
page-url=http://www.liferay.com page-url=http://www.liferay.com
author=Liferay, Inc. author=Liferay, Inc.
licenses=LGPL licenses=LGPL
liferay-versions=6.2.0 liferay-versions=6.2.0

portal-dependency-jars=\
commons-lang.jar
Expand Up @@ -32,6 +32,7 @@
import com.liferay.resourcesimporter.util.Importer; import com.liferay.resourcesimporter.util.Importer;
import com.liferay.resourcesimporter.util.ImporterException; import com.liferay.resourcesimporter.util.ImporterException;
import com.liferay.resourcesimporter.util.LARImporter; import com.liferay.resourcesimporter.util.LARImporter;
import com.liferay.resourcesimporter.util.PortletPropsValues;
import com.liferay.resourcesimporter.util.ResourceImporter; import com.liferay.resourcesimporter.util.ResourceImporter;


import java.io.IOException; import java.io.IOException;
Expand All @@ -45,6 +46,8 @@


import javax.servlet.ServletContext; import javax.servlet.ServletContext;


import org.apache.commons.lang.time.StopWatch;

/** /**
* @author Ryan Park * @author Ryan Park
* @author Raymond Augé * @author Raymond Augé
Expand Down Expand Up @@ -137,7 +140,9 @@ else if ((resourcePaths != null) && !resourcePaths.isEmpty()) {


importer.afterPropertiesSet(); importer.afterPropertiesSet();


if (importer.getGroupId() == 0) { if (!PortletPropsValues.DEVELOPER_MODE_ENABLED &&
importer.isExisting()) {

if (_log.isInfoEnabled()) { if (_log.isInfoEnabled()) {
_log.info( _log.info(
"Group or layout set prototype already exists " + "Group or layout set prototype already exists " +
Expand All @@ -147,14 +152,23 @@ else if ((resourcePaths != null) && !resourcePaths.isEmpty()) {
continue; continue;
} }


StopWatch stopWatch = null;

if (_log.isInfoEnabled()) { if (_log.isInfoEnabled()) {
_log.info( stopWatch = new StopWatch();
"Importing resources from " + servletContextName +
" to group " + importer.getGroupId()); stopWatch.start();
} }


importer.importResources(); importer.importResources();


if (_log.isInfoEnabled()) {
_log.info(
"Importing resources from " + servletContextName +
" to group " + importer.getGroupId() + " takes " +
stopWatch.getTime() + " ms");
}

Message newMessage = new Message(); Message newMessage = new Message();


newMessage.put("companyId", company.getCompanyId()); newMessage.put("companyId", company.getCompanyId());
Expand Down
Expand Up @@ -51,25 +51,31 @@ public void afterPropertiesSet() throws Exception {
Group group = null; Group group = null;


if (targetClassName.equals(LayoutSetPrototype.class.getName())) { if (targetClassName.equals(LayoutSetPrototype.class.getName())) {
if (!hasLayoutSetPrototype(companyId, targetValue)) { LayoutSetPrototype layoutSetPrototype = getLayoutSetPrototype(
LayoutSetPrototype layoutSetPrototype = companyId, targetValue);

if (layoutSetPrototype != null) {
existing = true;
}
else {
layoutSetPrototype =
LayoutSetPrototypeLocalServiceUtil.addLayoutSetPrototype( LayoutSetPrototypeLocalServiceUtil.addLayoutSetPrototype(
userId, companyId, getTargetValueMap(), userId, companyId, getTargetValueMap(),
StringPool.BLANK, true, true, new ServiceContext()); StringPool.BLANK, true, true, new ServiceContext());
}


group = layoutSetPrototype.getGroup(); group = layoutSetPrototype.getGroup();


privateLayout = true; privateLayout = true;
targetClassPK = layoutSetPrototype.getLayoutSetPrototypeId(); targetClassPK = layoutSetPrototype.getLayoutSetPrototypeId();
}
} }
else if (targetClassName.equals(Group.class.getName())) { else if (targetClassName.equals(Group.class.getName())) {
if (targetValue.equals(GroupConstants.GUEST)) { if (targetValue.equals(GroupConstants.GUEST)) {
Group guestGroup = GroupLocalServiceUtil.getGroup( group = GroupLocalServiceUtil.getGroup(
companyId, GroupConstants.GUEST); companyId, GroupConstants.GUEST);


List<Layout> layouts = LayoutLocalServiceUtil.getLayouts( List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(
guestGroup.getGroupId(), false, group.getGroupId(), false,
LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, false, 0, 1); LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, false, 0, 1);


if (!layouts.isEmpty()) { if (!layouts.isEmpty()) {
Expand All @@ -81,39 +87,41 @@ else if (targetClassName.equals(Group.class.getName())) {
List<String> portletIds = layoutTypePortlet.getPortletIds(); List<String> portletIds = layoutTypePortlet.getPortletIds();


if (portletIds.size() != 2) { if (portletIds.size() != 2) {
return; existing = true;
} }


for (String portletId : portletIds) { for (String portletId : portletIds) {
if (!portletId.equals("47") && if (!portletId.equals("47") &&
!portletId.equals("58")) { !portletId.equals("58")) {


return; existing = true;
} }
} }
} }

group = guestGroup;
}
else if (!hasGroup(companyId, targetValue)) {
group = GroupLocalServiceUtil.addGroup(
userId, GroupConstants.DEFAULT_PARENT_GROUP_ID,
StringPool.BLANK, 0, targetValue, StringPool.BLANK,
GroupConstants.TYPE_SITE_OPEN, null, true, true,
new ServiceContext());
} }
else {
group = GroupLocalServiceUtil.fetchGroup(
companyId, targetValue);


if (group != null) { if (group != null) {
privateLayout = false; existing = true;
targetClassPK = group.getGroupId(); }
else {
group = GroupLocalServiceUtil.addGroup(
userId, GroupConstants.DEFAULT_PARENT_GROUP_ID,
StringPool.BLANK, 0, targetValue, StringPool.BLANK,
GroupConstants.TYPE_SITE_OPEN, null, true, true,
new ServiceContext());
}
} }
}


if (group == null) { privateLayout = false;
return; targetClassPK = group.getGroupId();
} }


groupId = group.getGroupId(); if (group != null) {
groupId = group.getGroupId();
}
} }


public long getGroupId() { public long getGroupId() {
Expand All @@ -134,6 +142,10 @@ public Map<Locale, String> getTargetValueMap() {
return targetValueMap; return targetValueMap;
} }


public boolean isExisting() {
return existing;
}

public void setCompanyId(long companyId) { public void setCompanyId(long companyId) {
this.companyId = companyId; this.companyId = companyId;
} }
Expand All @@ -158,17 +170,8 @@ public void setTargetValue(String targetValue) {
this.targetValue = targetValue; this.targetValue = targetValue;
} }


protected boolean hasGroup(long companyId, String name) throws Exception { protected LayoutSetPrototype getLayoutSetPrototype(
Group group = GroupLocalServiceUtil.fetchGroup(companyId, name); long companyId, String name)

if (group != null) {
return true;
}

return false;
}

protected boolean hasLayoutSetPrototype(long companyId, String name)
throws Exception { throws Exception {


Locale locale = LocaleUtil.getDefault(); Locale locale = LocaleUtil.getDefault();
Expand All @@ -179,14 +182,15 @@ protected boolean hasLayoutSetPrototype(long companyId, String name)


for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) { for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
if (name.equals(layoutSetPrototype.getName(locale))) { if (name.equals(layoutSetPrototype.getName(locale))) {
return true; return layoutSetPrototype;
} }
} }


return false; return null;
} }


protected long companyId; protected long companyId;
protected boolean existing;
protected long groupId; protected long groupId;
protected boolean privateLayout; protected boolean privateLayout;
protected String resourcesDir; protected String resourcesDir;
Expand Down
Expand Up @@ -35,6 +35,7 @@
import com.liferay.portal.service.LayoutLocalServiceUtil; import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.service.LayoutSetLocalServiceUtil; import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.LayoutSetPrototypeLocalServiceUtil; import com.liferay.portal.service.LayoutSetPrototypeLocalServiceUtil;
import com.liferay.portal.service.RepositoryLocalServiceUtil;
import com.liferay.portal.service.ServiceContext; import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ThemeLocalServiceUtil; import com.liferay.portal.service.ThemeLocalServiceUtil;
import com.liferay.portal.util.PortalUtil; import com.liferay.portal.util.PortalUtil;
Expand Down Expand Up @@ -416,7 +417,8 @@ protected void doAddJournalStructures(
nameMap, null, xsd, serviceContext); nameMap, null, xsd, serviceContext);


addJournalTemplates( addJournalTemplates(
journalStructure.getStructureId(), _JOURNAL_TEMPLATES_DIR_NAME + name); journalStructure.getStructureId(),
_JOURNAL_TEMPLATES_DIR_NAME + name);


if (Validator.isNull(parentStructureId)) { if (Validator.isNull(parentStructureId)) {
addJournalStructures( addJournalStructures(
Expand Down Expand Up @@ -590,6 +592,14 @@ protected String processJournalArticleContent(String content)
} }


protected void setupAssets() throws Exception { protected void setupAssets() throws Exception {
RepositoryLocalServiceUtil.deleteRepositories(groupId);

JournalArticleLocalServiceUtil.deleteArticles(groupId);

JournalTemplateLocalServiceUtil.deleteTemplates(groupId);

JournalStructureLocalServiceUtil.deleteStructures(groupId);

addDLFileEntries(_DL_DOCUMENTS_DIR_NAME); addDLFileEntries(_DL_DOCUMENTS_DIR_NAME);


addJournalArticles( addJournalArticles(
Expand Down Expand Up @@ -723,10 +733,10 @@ protected void updateLayoutSetThemeId(JSONObject sitemapJSONObject)


private static final String _JOURNAL_ARTICLES_DIR_NAME = private static final String _JOURNAL_ARTICLES_DIR_NAME =
"/journal/articles/"; "/journal/articles/";

private static final String _JOURNAL_STRUCTURES_DIR_NAME = private static final String _JOURNAL_STRUCTURES_DIR_NAME =
"/journal/structures/"; "/journal/structures/";

private static final String _JOURNAL_TEMPLATES_DIR_NAME = private static final String _JOURNAL_TEMPLATES_DIR_NAME =
"/journal/templates/"; "/journal/templates/";


Expand Down
Expand Up @@ -30,6 +30,8 @@ public interface Importer {


public void importResources() throws Exception; public void importResources() throws Exception;


public boolean isExisting();

public void setCompanyId(long companyId); public void setCompanyId(long companyId);


public void setResourcesDir(String resourcesDir); public void setResourcesDir(String resourcesDir);
Expand Down
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.resourcesimporter.util;

/**
* @author Shinn Lok
*/
public interface PortletPropsKeys {

public static final String DEVELOPER_MODE_ENABLED =
"developer.mode.enabled";

}
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.resourcesimporter.util;

import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.util.portlet.PortletProps;

/**
* @author Shinn Lok
*/
public class PortletPropsValues {

public static final boolean DEVELOPER_MODE_ENABLED = GetterUtil.getBoolean(
PortletProps.get(PortletPropsKeys.DEVELOPER_MODE_ENABLED));

}
@@ -0,0 +1,3 @@
include-and-override=portlet-ext.properties

developer.mode.enabled=false

0 comments on commit e8fe898

Please sign in to comment.