Skip to content

Commit

Permalink
Merge branch 'release/1.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuflatland-lf committed Dec 16, 2019
2 parents 65d733d + d307028 commit c5bd599
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jar {
manifest {
attributes(
"Bundle-SymbolicName": "com.liferay.damascus.cli",
"Bundle-Version": "1.1.4",
"Bundle-Version": "1.1.5",
"Bundle-Description": "Liferay extension tool for scaffolding service builder portlet",
"Main-Class": "com.liferay.damascus.cli.Damascus",
"JPM-Command": "damascus"
Expand Down
Binary file modified latest/damascus.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/com/liferay/damascus/cli/Damascus.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Slf4j
public class Damascus {

public final static String VERSION = "1.1.4";// + "_" + LocalDateTime.now().toString();
public final static String VERSION = "1.1.5";// + "_" + LocalDateTime.now().toString();

/**
* Main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ package ${packageName}.service.impl;

import com.liferay.asset.kernel.model.AssetEntry;
import com.liferay.asset.kernel.model.AssetLinkConstants;
import com.liferay.exportimport.kernel.lar.ExportImportThreadLocal;
import com.liferay.friendly.url.exception.DuplicateFriendlyURLEntryException;
import com.liferay.friendly.url.model.FriendlyURLEntry;
import com.liferay.friendly.url.service.FriendlyURLEntryLocalService;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.aop.AopService;
import com.liferay.portal.kernel.comment.CommentManagerUtil;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.log.Log;
Expand Down Expand Up @@ -263,6 +266,11 @@ public class ${capFirstModel}LocalServiceImpl extends ${capFirstModel}LocalServi

deleteDiscussion(entry);

// Friendly URL

_friendlyURLEntryLocalService.deleteFriendlyURLEntry(
entry.getGroupId(), ${capFirstModel}.class, entry.getPrimaryKey());

// Trash

_trashEntryLocalService.deleteEntry(
Expand Down Expand Up @@ -862,9 +870,7 @@ public class ${capFirstModel}LocalServiceImpl extends ${capFirstModel}LocalServi
${capFirstModel} entry = _updateEntry(
orgEntry.getPrimaryKey(), orgEntry, serviceContext);

if (entry.isPending() || entry.isDraft()) {
}
else {
if (!entry.isPending() && !entry.isDraft()) {
entry.setStatus(WorkflowConstants.STATUS_DRAFT);
}

Expand Down Expand Up @@ -1007,7 +1013,11 @@ public class ${capFirstModel}LocalServiceImpl extends ${capFirstModel}LocalServi
newEntry.setModifiedDate(now);

newEntry.setUuid(serviceContext.getUuid());
newEntry.setUrlTitle(getUniqueUrlTitle(entry, entry.get${application.asset.assetTitleFieldName?cap_first}()));

// Friendly URLs
String urlTitle = getUniqueUrlTitle(newEntry, entry.get${application.asset.assetTitleFieldName?cap_first}());
urlTitle = updateFriendlyURLs(newEntry, urlTitle, serviceContext);
newEntry.setUrlTitle(urlTitle);

newEntry.set${application.asset.assetTitleFieldName?cap_first}(entry.get${application.asset.assetTitleFieldName?cap_first}());
newEntry.set${application.asset.assetSummaryFieldName?cap_first}(entry.get${application.asset.assetSummaryFieldName?cap_first}());
Expand Down Expand Up @@ -1059,8 +1069,30 @@ public class ${capFirstModel}LocalServiceImpl extends ${capFirstModel}LocalServi
updateEntry.setModifiedDate(now);

updateEntry.setUuid(entry.getUuid());
String urlTitle = entry.get${application.asset.assetTitleFieldName?cap_first}();
if (Validator.isNotNull(urlTitle)) {
long classNameId = _classNameLocalService.getClassNameId(
${capFirstModel}.class);

try{
_friendlyURLEntryLocalService.validate(
entry.getGroupId(), classNameId, primaryKey, entry.get${application.asset.assetTitleFieldName?cap_first}());
} catch(DuplicateFriendlyURLEntryException e) {
List<String> error = new ArrayList<String>();
error.add("duplicated-url-title");
throw new ${capFirstModel}ValidateException(error);
}
}
else {
urlTitle = getUniqueUrlTitle(entry, urlTitle);
}

if (!urlTitle.equals(entry.getUrlTitle())) {
urlTitle = updateFriendlyURLs(entry, urlTitle, serviceContext);
}

updateEntry.setUrlTitle(
getUniqueUrlTitle(updateEntry, updateEntry.getUrlTitle()));
getUniqueUrlTitle(updateEntry, urlTitle));

updateEntry.set${application.asset.assetTitleFieldName?cap_first}(entry.get${application.asset.assetTitleFieldName?cap_first}());
updateEntry.set${application.asset.assetSummaryFieldName?cap_first}(entry.get${application.asset.assetSummaryFieldName?cap_first}());
Expand All @@ -1080,6 +1112,51 @@ public class ${capFirstModel}LocalServiceImpl extends ${capFirstModel}LocalServi
return updateEntry;
}

/**
* Update Friendly URLs
*
* @param entry ${capFirstModel}
* @param urlTitle
* @param serviceContext
* @return string
* @throws PortalException
*/
protected String updateFriendlyURLs(
${capFirstModel} entry, String urlTitle,
ServiceContext serviceContext)
throws PortalException {

if (ExportImportThreadLocal.isImportInProcess() ||
ExportImportThreadLocal.isStagingInProcess()) {

return urlTitle;
}

List<FriendlyURLEntry> friendlyURLEntries =
_friendlyURLEntryLocalService.getFriendlyURLEntries(
entry.getGroupId(),
classNameLocalService.getClassNameId(${capFirstModel}.class),
entry.getPrimaryKey());

FriendlyURLEntry newFriendlyURLEntry =
_friendlyURLEntryLocalService.addFriendlyURLEntry(
entry.getGroupId(),
classNameLocalService.getClassNameId(${capFirstModel}.class),
entry.getPrimaryKey(), urlTitle, serviceContext);

for (FriendlyURLEntry friendlyURLEntry : friendlyURLEntries) {
if (newFriendlyURLEntry.getFriendlyURLEntryId() ==
friendlyURLEntry.getFriendlyURLEntryId()) {

continue;
}

_friendlyURLEntryLocalService.deleteFriendlyURLEntry(friendlyURLEntry);
}

return newFriendlyURLEntry.getUrlTitle();
}

/**
* Delete discussion (comments)
*
Expand All @@ -1099,7 +1176,7 @@ public class ${capFirstModel}LocalServiceImpl extends ${capFirstModel}LocalServi

String urlTitle = null;

if (newTitle == null) {
if (newTitle == null || newTitle.equals("")) {
urlTitle = String.valueOf(entryId);
}
else {
Expand Down Expand Up @@ -1212,4 +1289,4 @@ public class ${capFirstModel}LocalServiceImpl extends ${capFirstModel}LocalServi
@Reference
private TrashEntryLocalService _trashEntryLocalService;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
package ${packageName}.service.util;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.ModelHintsUtil;
import com.liferay.portal.kernel.repository.model.ModelValidator;
import com.liferay.portal.kernel.util.Validator;
import ${packageName}.exception.${capFirstModel}ValidateException;
import ${packageName}.model.${capFirstModel};

Expand Down Expand Up @@ -49,13 +51,32 @@ public class ${capFirstModel}Validator implements ModelValidator<${capFirstModel
<#-- ---------------- -->
<#-- field loop ends -->
<#-- ---------------- -->
/* </dmsc:sync> */
/* </dmsc:sync> */
validate${application.asset.assetTitleFieldName?cap_first}(entry.get${application.asset.assetTitleFieldName?cap_first}());

if (0 < _errors.size()) {
throw new ${capFirstModel}ValidateException(_errors);
}

}

/**
* ${application.asset.assetTitleFieldName} field Validation
*
* @param ${application.asset.assetTitleFieldName}
*/
protected void validate${application.asset.assetTitleFieldName?cap_first}(String ${application.asset.assetTitleFieldName}) {
if (Validator.isNotNull(${application.asset.assetTitleFieldName})) {
int ${application.asset.assetTitleFieldName}MaxLength = ModelHintsUtil.getMaxLength(
${capFirstModel}.class.getName(), "${application.asset.assetTitleFieldName}");

if (${application.asset.assetTitleFieldName}.length() > ${application.asset.assetTitleFieldName}MaxLength) {
_errors.add("${application.asset.assetTitleFieldName} has more than " + ${application.asset.assetTitleFieldName}MaxLength +
" characters");
}
}
}

/* <dmsc:sync id="validate-methods" > */
<#-- ---------------- -->
<#-- field loop start -->
Expand Down Expand Up @@ -115,4 +136,4 @@ public class ${capFirstModel}Validator implements ModelValidator<${capFirstModel

protected List<String> _errors = new ArrayList<>();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ boolean fromAsset = ParamUtil.getBoolean(request, "fromAsset", false);
String CMD = ParamUtil.getString(request, Constants.CMD, Constants.UPDATE);
${capFirstModel} ${uncapFirstModel} = (${capFirstModel})request.getAttribute("${uncapFirstModel}");
String redirect = ParamUtil.getString(request, "redirect");
portletDisplay.setShowBackIcon(true);
portletDisplay.setURLBack(redirect);

%>

<liferay-frontend:info-bar
Expand Down Expand Up @@ -45,6 +48,8 @@ String redirect = ParamUtil.getString(request, "redirect");
<#-- Assets -->
<#-- ---------------- -->
<#if application.asset.assetTitleFieldName?? && application.asset.assetTitleFieldName != "" >
<liferay-ui:error key="duplicated-url-title"
message="duplicated-url-title" />
<aui:input name="${application.asset.assetTitleFieldName}" label="title" />
</#if>
<#if application.asset.assetSummaryFieldName?? && application.asset.assetSummaryFieldName != "" >
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/templates/7.2/Portlet_XXXXWEB_edit.jsp.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
String CMD = ParamUtil.getString(request, Constants.CMD, Constants.UPDATE);
${capFirstModel} ${uncapFirstModel} = (${capFirstModel})request.getAttribute("${uncapFirstModel}");
String redirect = ParamUtil.getString(request, "redirect");
portletDisplay.setShowBackIcon(true);
portletDisplay.setURLBack(redirect);
%>

<portlet:actionURL name="/${lowercaseModel}/crud" var="${lowercaseModel}EditURL">
Expand Down Expand Up @@ -49,6 +51,8 @@
<#-- Assets -->
<#-- ---------------- -->
<#if application.asset.assetTitleFieldName?? && application.asset.assetTitleFieldName != "" >
<liferay-ui:error key="duplicated-url-title"
message="duplicated-url-title" />
<aui:input name="${application.asset.assetTitleFieldName}" label="title" />
</#if>
<#if application.asset.assetSummaryFieldName?? && application.asset.assetSummaryFieldName != "" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<#assign skipTemplate = !generateWeb>
<!-- </dmsc:sync> -->
<routes>
<!--
<route>
<pattern></pattern>
<implicit-parameter name="mvcRenderCommandName">/${lowercaseModel}/view</implicit-parameter>
Expand Down Expand Up @@ -49,4 +50,5 @@
<implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
<implicit-parameter name="tag"></implicit-parameter>
</route>
-->
</routes>
Loading

0 comments on commit c5bd599

Please sign in to comment.