use of com.ableneo.liferay.portal.setup.domain.Document in project liferay-db-setup-core by ableneo.
the class SetupDocuments method setupSiteDocuments.
public static void setupSiteDocuments(final Site site, long groupId) {
for (Document doc : site.getDocument()) {
String folderPath = doc.getDocumentFolderName();
String documentName = doc.getDocumentFilename();
String documentTitle = doc.getDocumentTitle();
String filenameInFilesystem = doc.getFileSystemName();
long userId = SetupConfigurationThreadLocal.getRunAsUserId();
long company = SetupConfigurationThreadLocal.getRunInCompanyId();
switch(doc.getFileUploadType()) {
case GENERAL:
// groupid == site group (as-is)
break;
case LOGO_IMAGE:
// groupid = 'Control Panel' groups id..
try {
Group controlPanelGroup = GroupLocalServiceUtil.loadGetGroup(company, GroupConstants.CONTROL_PANEL);
groupId = controlPanelGroup.getGroupId();
} catch (PortalException e) {
LOG.error("Can not get group for " + GroupConstants.CONTROL_PANEL + " and company " + company + ":", e);
return;
}
break;
default:
LOG.error("Can not understand enum value '" + doc.getFileUploadType() + "' as upload-type.. check dependencies, implement on need!");
return;
}
long repoId = groupId;
FileEntry fe = DocumentUtil.findDocument(documentName, folderPath, groupId, groupId);
byte[] fileBytes = null;
try {
fileBytes = ResourcesUtil.getFileBytes(filenameInFilesystem);
} catch (IOException e) {
LOG.error(String.format("Can not read file: %1$s. Skipping file", filenameInFilesystem));
continue;
}
if (fileBytes != null) {
if (fe == null) {
Folder folder = null;
if (Validator.isBlank(folderPath)) {
folder = FolderUtil.findFolder(groupId, repoId, folderPath, true);
} else {
try {
folder = DLAppLocalServiceUtil.getMountFolder(repoId);
} catch (PortalException e) {
LOG.warn("Mount folder not found for file [{}], stopped creating the document.", documentName, e);
}
}
if (folder != null) {
LOG.info("{} is not found! It will be created! (c: {},grp: {}", documentName, company, groupId);
fe = DocumentUtil.createDocument(groupId, folder.getFolderId(), documentName, documentTitle, userId, repoId, fileBytes);
}
} else {
LOG.info(documentName + " is found! Content will be updated! (c:" + company + ",grp:" + groupId + " ");
DocumentUtil.updateFile(fe, fileBytes, userId, documentName);
}
SetupPermissions.updatePermission(String.format("Document %1$s/%2$s", folderPath, documentName), company, fe.getFileEntryId(), DLFileEntry.class, doc.getRolePermissions(), DEFAULT_PERMISSIONS);
}
}
}
Aggregations