|
|
|
@ -3,13 +3,19 @@ package org.gcube.portal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.liferay.portal.kernel.events.ActionException;
|
|
|
|
|
import com.liferay.portal.kernel.events.SimpleAction;
|
|
|
|
|
import com.liferay.portal.model.VirtualHost;
|
|
|
|
|
import com.liferay.portal.model.Group;
|
|
|
|
|
import com.liferay.portal.model.LayoutSet;
|
|
|
|
|
import com.liferay.portal.service.GroupLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.service.VirtualHostLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.util.PortalUtil;
|
|
|
|
|
|
|
|
|
|
public class ServletTrigger extends SimpleAction {
|
|
|
|
|
private static final Logger _log = LoggerFactory.getLogger(ServletTrigger.class);
|
|
|
|
@ -41,22 +47,48 @@ public class ServletTrigger extends SimpleAction {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<String> getVirtualHostURLs() {
|
|
|
|
|
_log.info("MAIL_PARSER STARTING ... getVirtualHostURLs() ");
|
|
|
|
|
List<String> toReturn = new ArrayList<String>();
|
|
|
|
|
List<VirtualHost> vHosts = null;
|
|
|
|
|
List<String> toReturn = new ArrayList<>();
|
|
|
|
|
_log.info("MAIL_PARSER STARTING ... getGateways() ");
|
|
|
|
|
GroupManager gm = new LiferayGroupManager();
|
|
|
|
|
List<Gateway> gateways = getGateways(gm);
|
|
|
|
|
try {
|
|
|
|
|
vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount());
|
|
|
|
|
for (VirtualHost virtualHost : vHosts) {
|
|
|
|
|
if (virtualHost.getHostname().compareTo("localhost") != 0 && virtualHost.getLayoutSetId() != 0) {
|
|
|
|
|
String hostToContact = PROTOCOL+virtualHost.getHostname();
|
|
|
|
|
toReturn.add(hostToContact);
|
|
|
|
|
_log.info("Added host to contact: " + hostToContact);
|
|
|
|
|
}
|
|
|
|
|
for (Gateway gateway : gateways) {
|
|
|
|
|
LayoutSet layoutSet = null;
|
|
|
|
|
Group childGroup = gateway.getSite();
|
|
|
|
|
if (childGroup.hasPublicLayouts())
|
|
|
|
|
layoutSet = childGroup.getPublicLayoutSet();
|
|
|
|
|
else
|
|
|
|
|
layoutSet = childGroup.getPrivateLayoutSet();
|
|
|
|
|
final long companyId = PortalUtil.getDefaultCompanyId();
|
|
|
|
|
long layoutSetId = layoutSet.getLayoutSetId();
|
|
|
|
|
String virtualHost = VirtualHostLocalServiceUtil.getVirtualHost(companyId, layoutSetId).getHostname();
|
|
|
|
|
String hostToContact = PROTOCOL+virtualHost;
|
|
|
|
|
toReturn.add(hostToContact);
|
|
|
|
|
_log.info("\n*** MAILReader - Added host to contact: " + hostToContact);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Gateway> getGateways(GroupManager groupsManager) {
|
|
|
|
|
List<Gateway> toReturn = new ArrayList<>();
|
|
|
|
|
try{
|
|
|
|
|
List<Group> candidateGateways = GroupLocalServiceUtil.getGroups(ManagementUtils.getCompany().getCompanyId(), 0, true);
|
|
|
|
|
// real gateways have no children as well
|
|
|
|
|
for (Group group : candidateGateways) {
|
|
|
|
|
List<Group> children = group.getChildren(true);
|
|
|
|
|
if(children == null || children.isEmpty())
|
|
|
|
|
if(! (group.getFriendlyURL().equals("/guest") || group.getFriendlyURL().equals("/global") )) {// skipping these sites
|
|
|
|
|
toReturn.add(new Gateway(group));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch(Exception e){
|
|
|
|
|
_log.error("Failed to retrieve the list of gateways", e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|