use of com.liferay.imex.site.model.ImexSite in project liferay-imex by jpdacunha.
the class SiteExporter method doExport.
private void doExport(long companyId, User user, Properties config, Locale locale, boolean debug, boolean privatePagesEnabled, boolean publicPagesEnabled, File sitesDir, Group group) throws PortalException, ImexException {
File siteDir = initializeSingleSiteExportDirectory(sitesDir, group, locale);
if (siteDir != null) {
if (siteDir.exists()) {
boolean privateLayout;
String groupName = GroupUtil.getGroupName(group, locale);
String parentGroupIdFriendlyUrl = null;
try {
parentGroupIdFriendlyUrl = siteCommonService.getParentSiteFriendlyURL(companyId, group.getParentGroupId());
processor.write(new ImexSite(group, parentGroupIdFriendlyUrl), siteDir, FileNames.getSiteFileName(group, processor.getFileExtension()));
} catch (NoSuchGroupException e1) {
reportService.getError(_log, groupName, "Site identified by [" + parentGroupIdFriendlyUrl + "] is a parent site an it does not exists. Maybe you can use [" + ImExSiteExporterPropsKeys.EXPORT_SITE_ORDER_FRIENDLYURL_LIST + "] to configure IMEX to import the parent site prior to child site.");
if (debug) {
_log.error(e1, e1);
}
} catch (Exception e) {
reportService.getError(_log, groupName, e);
if (debug) {
_log.error(e, e);
}
}
if (publicPagesEnabled) {
privateLayout = false;
doExportLar(user, config, group, siteDir, locale, privateLayout, debug);
}
if (privatePagesEnabled) {
privateLayout = true;
doExportLar(user, config, group, siteDir, locale, privateLayout, debug);
}
reportService.getOK(_log, groupName, "SITE : " + groupName);
} else {
reportService.getDNE(_log, siteDir.getAbsolutePath());
}
} else {
_log.error("siteDir is null ...");
}
}
use of com.liferay.imex.site.model.ImexSite in project liferay-imex by jpdacunha.
the class SiteImporter method doUpdateSiteDatas.
private void doUpdateSiteDatas(long companyId, User user, Properties config, File groupDir, Locale locale, Map<String, String> toUpdateParentGroups, boolean debug) throws Exception {
if (groupDir != null) {
if (groupDir.exists()) {
String dirName = groupDir.getName();
String groupFriendlyUrl = ImexNormalizer.getFriendlyURLByDirName(dirName);
reportService.getStartMessage(_log, groupFriendlyUrl);
String siteDescriptorFileName = FileNames.getSiteFileName(groupFriendlyUrl, processor.getFileExtension());
ImexSite imexSite = (ImexSite) processor.read(ImexSite.class, groupDir, siteDescriptorFileName);
UnicodeProperties typeSettingsProperties = imexSite.getUnicodeProperties();
ServiceContext serviceContext = new ServiceContext();
boolean site = imexSite.isSite();
long userId = user.getUserId();
String className = imexSite.getClassName();
long classPK = imexSite.getClassPK();
Map<Locale, String> nameMap = imexSite.getNameMap();
Map<Locale, String> descriptionMap = imexSite.getDescriptionMap();
int type = imexSite.getType();
String friendlyURL = imexSite.getFriendlyURL();
boolean active = imexSite.isActive();
int membershipRestriction = imexSite.getMemberShipRestriction();
boolean manualMembership = imexSite.isManualMemberShip();
boolean inheritContent = imexSite.isInheritContent();
long liveGroupId = GroupConstants.DEFAULT_LIVE_GROUP_ID;
long defaultParentGroupId = GroupConstants.DEFAULT_PARENT_GROUP_ID;
String logPrefix = "SITE : " + groupFriendlyUrl;
Group group = groupLocalService.fetchFriendlyURLGroup(companyId, friendlyURL);
if (group == null) {
OnMissingSiteMethodEnum createMethod = behaviorManagerService.getOnMissingBehavior(config, groupFriendlyUrl);
if (createMethod.getValue().equals(OnMissingSiteMethodEnum.CREATE.getValue())) {
String stringList = GetterUtil.getString(config.get(ImExSiteImporterPropsKeys.IMPORT_SITE_LIFERAY_SYSTEM_GROUPS_FRIENDLYURL_LIST));
List<String> neverCreateFriendlyURLS = CollectionUtil.getList(stringList);
if (neverCreateFriendlyURLS.contains(groupFriendlyUrl)) {
reportService.getError(_log, groupFriendlyUrl, "is evaluated as [" + OnMissingSiteMethodEnum.CREATE.getValue() + "] but it appears to be a system group. Skipping creation");
getReportService().getSkipped(_log, groupFriendlyUrl);
} else {
group = groupLocalService.addGroup(userId, defaultParentGroupId, className, classPK, liveGroupId, nameMap, descriptionMap, type, manualMembership, membershipRestriction, friendlyURL, site, active, serviceContext);
groupLocalService.updateGroup(group.getGroupId(), typeSettingsProperties.toString());
doImportLars(groupDir, config, user, group, locale, debug);
reportService.getOK(_log, dirName, logPrefix, createMethod.getValue());
}
} else {
_log.debug("Site creation were skipped.");
getReportService().getSkipped(_log, groupFriendlyUrl);
}
} else {
OnExistsSiteMethodEnum duplicateMethod = behaviorManagerService.getOnExistsBehavior(config, group);
if (!duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.SKIP.getValue())) {
if (duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.UPDATE_GROUP_ONLY.getValue())) {
updateLiferayGroup(typeSettingsProperties, serviceContext, nameMap, descriptionMap, type, friendlyURL, active, membershipRestriction, manualMembership, inheritContent, defaultParentGroupId, group);
} else {
// Si le group existe
if (duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.UPDATE.getValue())) {
updateLiferayGroup(typeSettingsProperties, serviceContext, nameMap, descriptionMap, type, friendlyURL, active, membershipRestriction, manualMembership, inheritContent, defaultParentGroupId, group);
} else if (duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.RECREATE.getValue())) {
// Reseting parent group
siteCommonService.eraseSiteHierarchy(group);
// Deleting site
group = groupLocalService.deleteGroup(group);
// Creating site again
group = groupLocalService.addGroup(userId, defaultParentGroupId, className, classPK, liveGroupId, nameMap, descriptionMap, type, manualMembership, membershipRestriction, friendlyURL, site, active, serviceContext);
} else if (duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.DELETE.getValue())) {
// Reseting parent group
siteCommonService.eraseSiteHierarchy(group);
// Deleting site
group = groupLocalService.deleteGroup(group);
}
// Importing LARS
doImportLars(groupDir, config, user, group, locale, debug);
groupLocalService.updateGroup(group.getGroupId(), typeSettingsProperties.toString());
}
reportService.getOK(_log, dirName, logPrefix, duplicateMethod.getValue());
} else {
getReportService().getSkipped(_log, groupFriendlyUrl);
}
}
// Registering sites hierarchy to update
String parentGroupIdFriendlyUrl = imexSite.getParentGroupIdFriendlyUrl();
if (group != null && Validator.isNotNull(parentGroupIdFriendlyUrl)) {
toUpdateParentGroups.put(groupFriendlyUrl, parentGroupIdFriendlyUrl);
} else {
_log.debug("Site identified by [" + groupFriendlyUrl + "] has no parent group");
}
reportService.getEndMessage(_log, groupFriendlyUrl);
} else {
reportService.getDNE(_log, groupDir.getAbsolutePath());
}
} else {
_log.error("Skipping null dir ...");
}
}
Aggregations