Search in sources :

Example 1 with ExtendedImexVirtualhost

use of com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost in project liferay-imex by jpdacunha.

the class VirtualhostImporter method converToUpdatableMap.

private Map<Long, TreeMap<String, String>> converToUpdatableMap(long companyId, List<ExtendedImexVirtualhost> virtualHosts) throws PortalException {
    // Constructing structured map to update
    Map<Long, TreeMap<String, String>> layoutSetHostnames = new HashMap<Long, TreeMap<String, String>>();
    for (ExtendedImexVirtualhost extendedVirtualHostObj : virtualHosts) {
        ImexVirtualhost virtualHostObj = extendedVirtualHostObj.getVirtualhost();
        String companyWebId = virtualHostObj.getCompanyWebId();
        String groupFriendlyURL = virtualHostObj.getGroupFriendlyURL();
        boolean isPublicVirtualHost = virtualHostObj.isPublicVirtualHost();
        long layoutSetId = VirtualhostCommonService.DEFAULT_LAYOUTSET_ID;
        boolean isCompanyVirtualHost = virtualHostObj.isCompanyVirtualHost();
        File virtualHostFile = extendedVirtualHostObj.getSourceFile();
        String originFileName = virtualHostFile.getName();
        String languageId = virtualHostObj.getLanguageId();
        try {
            // Verify if company exists
            companyLocalService.getCompanyByWebId(companyWebId);
            if (!isCompanyVirtualHost) {
                // Verify if group exists
                Group group = groupLocalService.getFriendlyURLGroup(companyId, groupFriendlyURL);
                LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(group.getGroupId(), !isPublicVirtualHost);
                layoutSetId = layoutSet.getLayoutSetId();
            }
            String hostname = virtualHostObj.getHostname();
            TreeMap<String, String> currentLayoutSetHostnames = null;
            if (Validator.isNotNull(hostname)) {
                TreeMap<String, String> treeMap = layoutSetHostnames.get(layoutSetId);
                if (treeMap == null) {
                    layoutSetHostnames.put(layoutSetId, new TreeMap<String, String>());
                } else {
                    _log.debug("Updating existing TreeMap");
                }
                currentLayoutSetHostnames = layoutSetHostnames.get(layoutSetId);
                if (!currentLayoutSetHostnames.containsKey(hostname)) {
                    currentLayoutSetHostnames.put(hostname, languageId);
                } else {
                    _log.debug("Current TreeMap already contains [" + hostname + "]");
                }
            } else {
                reportService.getError(_log, originFileName, "missing required information hostname");
            }
        } catch (NoSuchCompanyException e) {
            reportService.getDNE(_log, "company identified by [" + companyWebId + "]");
            reportService.getSkipped(_log, originFileName);
        } catch (NoSuchGroupException e) {
            reportService.getDNE(_log, "group identified by [" + groupFriendlyURL + "]");
            reportService.getSkipped(_log, originFileName);
        }
    }
    return layoutSetHostnames;
}
Also used : Group(com.liferay.portal.kernel.model.Group) HashMap(java.util.HashMap) NoSuchCompanyException(com.liferay.portal.kernel.exception.NoSuchCompanyException) TreeMap(java.util.TreeMap) NoSuchGroupException(com.liferay.portal.kernel.exception.NoSuchGroupException) ImexVirtualhost(com.liferay.imex.virtualhost.model.ImexVirtualhost) ExtendedImexVirtualhost(com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost) ExtendedImexVirtualhost(com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost) File(java.io.File) LayoutSet(com.liferay.portal.kernel.model.LayoutSet)

Example 2 with ExtendedImexVirtualhost

use of com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost in project liferay-imex by jpdacunha.

the class VirtualhostImporter method deserialiseFiles.

private List<ExtendedImexVirtualhost> deserialiseFiles(File srcDir) throws Exception {
    File[] files = FileUtil.listFilesByExtension(srcDir, processor.getFileExtension());
    // Constructing deserialized list
    List<ExtendedImexVirtualhost> virtualHosts = new ArrayList<ExtendedImexVirtualhost>();
    for (File virtualHostFile : files) {
        ImexVirtualhost virtualHostObj = (ImexVirtualhost) processor.read(ImexVirtualhost.class, virtualHostFile);
        virtualHosts.add(new ExtendedImexVirtualhost(virtualHostFile, virtualHostObj));
    }
    if (virtualHosts.size() > 0) {
        // Ordering Default virtualhosts first
        Collections.sort(virtualHosts, new Comparator<ExtendedImexVirtualhost>() {

            @Override
            public int compare(ExtendedImexVirtualhost mall1, ExtendedImexVirtualhost mall2) {
                boolean b1 = mall1.isDefaultVirtualHost();
                boolean b2 = mall2.isDefaultVirtualHost();
                return Boolean.compare(b1, b2);
            }
        });
    }
    return virtualHosts;
}
Also used : ImexVirtualhost(com.liferay.imex.virtualhost.model.ImexVirtualhost) ExtendedImexVirtualhost(com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost) ExtendedImexVirtualhost(com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

ExtendedImexVirtualhost (com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost)2 ImexVirtualhost (com.liferay.imex.virtualhost.model.ImexVirtualhost)2 File (java.io.File)2 NoSuchCompanyException (com.liferay.portal.kernel.exception.NoSuchCompanyException)1 NoSuchGroupException (com.liferay.portal.kernel.exception.NoSuchGroupException)1 Group (com.liferay.portal.kernel.model.Group)1 LayoutSet (com.liferay.portal.kernel.model.LayoutSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1