use of com.liferay.dynamic.data.mapping.model.DDMTemplate in project liferay-db-setup-core by ableneo.
the class SetupPages method addMenuViewPortletIntoPage.
private static void addMenuViewPortletIntoPage(PageType page, Layout layout, MenuViewPortletType portlet, long companyId, long groupId) throws PortalException {
if (isLinkPage(page)) {
LOG.info(" ! SKIP-page is a link");
return;
}
LOG.info("Adding MenuViewPortlet: " + portlet.getColumn() + "@" + portlet.getColumnPosition() + "-" + portlet.getPortletId() + "; " + portlet.getAdtTemplate() + ":" + portlet.getMenuName());
PagePortletType toInsert = null;
Long menuId = getMenuIdByName(groupId, portlet.getMenuName());
if (menuId == null || menuId == 0L) {
LOG.info(" ! SKIP-no such menu to add");
return;
}
portlet.getPortletPreference().add(newPortletPreference("siteNavigationMenuId", String.valueOf(menuId)));
DDMTemplate adtTemplate = getAdtTemplate(groupId, portlet.getAdtTemplate(), portlet.getAdtTemplateSiteUrl());
if (adtTemplate == null) {
LOG.info(" ! SKIP-no such template to display with");
return;
}
portlet.getPortletPreference().add(newPortletPreference("displayStyle", "ddmTemplate_" + portlet.getAdtTemplate()));
Group group = GroupLocalServiceUtil.getFriendlyURLGroup(companyId, portlet.getAdtTemplateSiteUrl());
portlet.getPortletPreference().add(//
newPortletPreference("displayStyleGroupId", String.valueOf(group.getPrimaryKey())));
toInsert = new PagePortletType();
toInsert.setColumn(portlet.getColumn());
toInsert.setColumnPosition(portlet.getColumnPosition());
toInsert.setPortletId(portlet.getPortletId());
toInsert.setRolePermissions(portlet.getRolePermissions());
for (Entry<String, String> e : CONFIG_MENU_VIEW_PREFERENCES.entrySet()) {
toInsert.getPortletPreference().add(newPortletPreference(e.getKey(), e.getValue()));
}
toInsert.getPortletPreference().addAll(portlet.getPortletPreference());
insertPortletIntoPage(page, layout, toInsert, companyId, groupId);
}
use of com.liferay.dynamic.data.mapping.model.DDMTemplate in project liferay-imex by jpdacunha.
the class WcDDMExporter method doExport.
public void doExport(Properties config, Group group, File groupsDir, Locale locale, List<ExporterRawContent> rawContentToExport, boolean debug) throws ImexException {
if (group != null) {
// String groupName = GroupUtil.getGroupName(group, locale);
long classNameId = classNameLocalService.getClassNameId(JournalArticle.class);
List<DDMStructure> ddmStructures = dDMStructureLocalService.getStructures(group.getGroupId(), classNameId);
if (ddmStructures != null && ddmStructures.size() > 0) {
File groupDir = initializeSingleGroupDirectory(groupsDir, group);
if (groupDir != null) {
if (groupDir.exists()) {
// Iterate over structures
for (DDMStructure ddmStructure : ddmStructures) {
File structureDir = initializeSingleWCDDMExportDirectory(groupDir, ddmStructure);
if (structureDir != null) {
if (structureDir.exists()) {
try {
writeStructure(group, locale, rawContentToExport, ddmStructure, structureDir);
String groupName = GroupUtil.getGroupName(group, locale);
reportService.getOK(_log, groupName, "STRUCTURE : " + ddmStructure.getName(locale));
List<DDMTemplate> ddmTemplates = dDMTemplateLocalService.getTemplatesByClassPK(ddmStructure.getGroupId(), ddmStructure.getPrimaryKey());
// Iterate over templates
for (DDMTemplate ddmTemplate : ddmTemplates) {
writeTemplate(group, locale, rawContentToExport, structureDir, groupName, ddmTemplate);
reportService.getOK(_log, groupName, "TEMPLATE : " + ddmTemplate.getName(locale));
}
reportService.getSeparator(_log);
} catch (Exception e) {
reportService.getError(_log, ddmStructure.getName(locale), e);
if (debug) {
_log.error(e, e);
}
}
} else {
reportService.getDNE(_log, structureDir.getAbsolutePath());
}
} else {
_log.error("structureDir is null ...");
}
}
} else {
reportService.getDNE(_log, groupDir.getAbsolutePath());
}
} else {
_log.error("groupDir is null ...");
}
} else {
reportService.getEmpty(_log, group, locale);
}
} else {
_log.error("Skipping null group ...");
}
}
use of com.liferay.dynamic.data.mapping.model.DDMTemplate in project liferay-imex by jpdacunha.
the class WcDDMImporter method doImportTemplate.
private DDMTemplate doImportTemplate(Properties config, ServiceContext serviceContext, boolean debug, Group group, User user, Locale locale, File structureDir, DDMStructure structure) {
DDMTemplate template = null;
String templatefileBegin = FileNames.getTemplateFileNameBegin();
File[] templateFiles = FileUtil.listFiles(structureDir, templatefileBegin);
String groupName = GroupUtil.getGroupName(group, locale);
ServiceContext serviceContextTem = (ServiceContext) serviceContext.clone();
if (templateFiles != null || (templateFiles != null && templateFiles.length == 0)) {
for (File matchingTemplateFile : Arrays.asList(templateFiles)) {
String templateFileName = matchingTemplateFile.getName();
File templateFile = new File(structureDir, templateFileName);
ImexOperationEnum operation = ImexOperationEnum.UPDATE;
try {
ImExTemplate imexTemplate = (ImExTemplate) processor.read(ImExTemplate.class, templateFile);
Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(imexTemplate.getName());
Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(imexTemplate.getDescription());
long userId = user.getUserId();
String type = imexTemplate.getTemplateType();
String mode = null;
String language = imexTemplate.getLangType();
String script = imexTemplate.getData();
boolean cacheable = imexTemplate.isCacheable();
long classPK = 0;
if (structure != null) {
classPK = structure.getStructureId();
}
serviceContextTem.setAddGroupPermissions(true);
serviceContextTem.setAddGuestPermissions(true);
long groupId = group.getGroupId();
try {
// Searching for existing template
template = dDMTemplateLocalService.getDDMTemplateByUuidAndGroupId(imexTemplate.getUuid(), groupId);
long templateId = template.getTemplateId();
dDMTemplateLocalService.updateTemplate(userId, templateId, classPK, nameMap, descriptionMap, type, mode, language, script, cacheable, serviceContextTem);
} catch (NoSuchTemplateException e) {
long classNameId = classNameLocalService.getClassNameId(DDMStructure.class);
long resourceClassNameId = classNameLocalService.getClassNameId(JournalArticle.class);
String templateKey = imexTemplate.getKey();
boolean smallImage = false;
String smallImageURL = null;
File smallImageFile = null;
try {
template = dDMTemplateLocalService.addTemplate(userId, groupId, classNameId, classPK, resourceClassNameId, templateKey, nameMap, descriptionMap, type, mode, language, script, cacheable, smallImage, smallImageURL, smallImageFile, serviceContextTem);
operation = ImexOperationEnum.CREATE;
} catch (TemplateDuplicateTemplateKeyException e1) {
// In case of different template with same key exists => apply custom behavior or not
String behaviorValue = GetterUtil.getString(config.get(ImExWCDDmImporterPropsKeys.IMPORT_TEMPLATE_ON_KEY_EXISTS));
OnExistsTemplateMethodEnum duplicateMethod = OnExistsTemplateMethodEnum.fromValue(behaviorValue);
if (duplicateMethod.getValue().equals(OnExistsTemplateMethodEnum.UPDATE_EXISTING_TEMPLATE_BY_KEY.getValue())) {
template = dDMTemplateLocalService.getTemplate(groupId, classNameId, templateKey);
long templateId = template.getTemplateId();
dDMTemplateLocalService.updateTemplate(userId, templateId, classPK, nameMap, descriptionMap, type, mode, language, script, cacheable, serviceContextTem);
} else {
reportService.getError(_log, templateFile.getName(), " a template with the same key [" + templateKey + "] already exists. Please see [" + ImExWCDDmImporterPropsKeys.IMPORT_STRUCTURE_ON_KEY_EXISTS + "] parameter to customize this behavior.");
throw new TemplateDuplicateTemplateKeyException(e1);
}
}
}
reportService.getOK(_log, groupName, "[TEMPLATE : " + template.getName(locale) + " => STRUCTURE : " + structure.getName(locale) + "]", templateFile, operation);
} catch (Exception e) {
reportService.getError(_log, templateFile.getName(), e);
if (debug) {
_log.error(e, e);
}
}
}
} else {
reportService.getMessage(_log, "Missing templates", "No files found matching [" + templatefileBegin + "]");
}
return template;
}
use of com.liferay.dynamic.data.mapping.model.DDMTemplate in project liferay-imex by jpdacunha.
the class AdtImporter method doImportAdt.
private DDMTemplate doImportAdt(Bundle bundle, ServiceContext serviceContext, boolean debug, Group group, User user, Locale locale, File adtDir, Properties config) {
DDMTemplate template = null;
String adtfileBegin = FileNames.getAdtFileNameBegin();
ServiceContext serviceContextTem = (ServiceContext) serviceContext.clone();
String groupName = GroupUtil.getGroupName(group, locale);
File[] adtFiles = FileUtil.listFiles(adtDir, adtfileBegin);
if (adtFiles != null || (adtFiles != null && adtFiles.length == 0)) {
for (File matchingAdtFile : Arrays.asList(adtFiles)) {
String templateFileName = matchingAdtFile.getName();
File adtFile = new File(adtDir, templateFileName);
ImexOperationEnum operation = ImexOperationEnum.UPDATE;
try {
ImExAdt imexAdt = (ImExAdt) processor.read(ImExAdt.class, adtFile);
long classNameId = classNameLocalService.getClassNameId(imexAdt.getClassName());
// Liferay trap here :-) : the ressourceClassNameId is the name of the portlet. Potential problem here if the class is moved in future Liferay versions.
long resourceClassNameId = classNameLocalService.getClassNameId(RESOURCE_CLASSNAME);
Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(imexAdt.getName());
Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(imexAdt.getDescription());
long userId = user.getUserId();
String type = imexAdt.getTemplateType();
String mode = null;
String language = imexAdt.getLangType();
String script = imexAdt.getData();
boolean cacheable = imexAdt.isCacheable();
long classPK = 0;
serviceContextTem.setUuid(imexAdt.getUuid());
serviceContextTem.setAddGroupPermissions(false);
serviceContextTem.setAddGuestPermissions(false);
try {
// Searching for existing template
template = dDMTemplateLocalService.getDDMTemplateByUuidAndGroupId(imexAdt.getUuid(), group.getGroupId());
long templateId = template.getTemplateId();
dDMTemplateLocalService.updateTemplate(userId, templateId, classPK, nameMap, descriptionMap, type, mode, language, script, cacheable, serviceContextTem);
} catch (NoSuchTemplateException e) {
long groupId = group.getGroupId();
String templateKey = "imex-" + imexAdt.getKey() + "-" + counterLocalService.increment();
boolean smallImage = false;
String smallImageURL = null;
File smallImageFile = null;
template = dDMTemplateLocalService.addTemplate(userId, groupId, classNameId, classPK, resourceClassNameId, templateKey, nameMap, descriptionMap, type, mode, language, script, cacheable, smallImage, smallImageURL, smallImageFile, serviceContextTem);
operation = ImexOperationEnum.CREATE;
}
// Setting ADT permissions
Resource resource = resourceLocalService.getResource(template.getCompanyId(), DDMTemplate.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, template.getTemplateId() + "");
permissionSetter.setPermissions(config, bundle, resource);
reportService.getOK(_log, groupName, "ADT : " + template.getName(locale), adtFile, operation);
} catch (Exception e) {
reportService.getError(_log, adtFile.getName(), e);
if (debug) {
_log.error(e, e);
}
}
}
} else {
reportService.getMessage(_log, "Missing templates", "No files found matching [" + adtfileBegin + "]");
}
return template;
}
use of com.liferay.dynamic.data.mapping.model.DDMTemplate in project liferay-imex by jpdacunha.
the class AdtExporter method doExport.
public void doExport(Properties config, Group group, File groupsDir, Locale locale, boolean debug, String classType, List<ExporterRawContent> rawContentToExport) throws ImexException {
if (group != null) {
long classNameId = classNameLocalService.getClassNameId(classType);
List<DDMTemplate> adts = dDMTemplateLocalService.getTemplates(group.getGroupId(), classNameId);
if (adts != null && adts.size() > 0) {
File groupDir = initializeSingleGroupDirectory(groupsDir, group);
if (groupDir != null) {
if (groupDir.exists()) {
// Iterate over structures
for (DDMTemplate ddmTemplate : adts) {
File adtDir = initializeSingleAdtExportDirectory(groupDir, classType);
if (adtDir != null) {
if (adtDir.exists()) {
try {
String groupName = GroupUtil.getGroupName(group, locale);
ImExAdt imexAdt = new ImExAdt(ddmTemplate, classType);
processor.write(imexAdt, adtDir, FileNames.getAdtFileName(ddmTemplate, locale, processor.getFileExtension()));
String rawFileName = FileNames.getGroupAdtFileName(ddmTemplate, group, locale, StringPool.PERIOD + imexAdt.getLangType());
rawContentToExport.add(new ExporterRawContent(rawFileName, imexAdt.getData()));
reportService.getOK(_log, groupName, "ADT : " + ddmTemplate.getName(locale) + ", type : " + classType);
} catch (Exception e) {
reportService.getError(_log, ddmTemplate.getName(locale), e);
if (debug) {
_log.error(e, e);
}
}
} else {
reportService.getDNE(_log, adtDir.getAbsolutePath());
}
} else {
_log.error("adtDir is null ...");
}
}
} else {
reportService.getDNE(_log, groupDir.getAbsolutePath());
}
} else {
_log.error("groupDir is null ...");
}
} else {
reportService.getEmpty(_log, group, locale, classType);
}
} else {
_log.error("Skipping null group ...");
}
}
Aggregations