You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.5 KiB
Java

package org.gcube.portlets.admin.systemservicedefinition.is;
import java.util.List;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class InformationSystemUtils {
private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class);
public static void retrieveSSD(String category, String scope, String token) throws Exception {
try {
logger.debug("Retrieve System Services Definition on IS");
if (scope == null || scope.isEmpty())
throw new Exception("Invalid scope: " + scope);
if (token == null || token.isEmpty())
throw new Exception("Invalid token: " + scope);
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(token);
//
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq '" + category + "'");
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
logger.debug("Retrieved: " + resources);
/*
* String serviceAddress = null; ArrayList<ServiceInfoData> serviceProperties =
* new ArrayList<>();
*
* if (accessPointList != null && !accessPointList.isEmpty()) { for (int i = 0;
* i < accessPointList.size(); i++) { AccessPoint accessPoint =
* accessPointList.get(i); if (accessPoint != null) { if (i == 0) { if
* (accessPoint.address() != null && !accessPoint.address().isEmpty()) { String
* accessPointAddress = accessPoint.address(); int wpsWebProcessingServiceIndex
* = accessPointAddress .indexOf(Constants.WPSWebProcessingService); if
* (wpsWebProcessingServiceIndex > 0) { serviceAddress =
* accessPointAddress.substring(0, wpsWebProcessingServiceIndex); } } }
*
* String categoryDescription; if (accessPoint.description() == null &&
* accessPoint.description().isEmpty()) { categoryDescription =
* Constants.DATA_MINER_DEFAULT_SERVICE_INFO_CATEGORY; } else {
* categoryDescription = accessPoint.description(); }
*
* if (accessPoint.properties() != null && !accessPoint.propertyMap().isEmpty())
* { for (String key : accessPoint.propertyMap().keySet()) { Property property =
* accessPoint.propertyMap().get(key); if (property != null && property.name()
* != null && !property.name().isEmpty()) { if (property.name().contains(":")) {
* String[] propertyWithCategory = property.name().split(":"); if
* (propertyWithCategory.length >= 2) { serviceProperties.add(new
* ServiceInfoData(propertyWithCategory[1], property.value(),
* propertyWithCategory[0])); } else { serviceProperties.add(new
* ServiceInfoData(property.name(), property.value(), categoryDescription)); } }
* else { serviceProperties.add(new ServiceInfoData(property.name(),
* property.value(), categoryDescription)); } }
*
* } } } } } ServiceInfo serviceInfo = new ServiceInfo(serviceAddress,
* serviceProperties);
*
* logger.debug("DataMiner Service Info: " + serviceInfo); return serviceInfo;
*/
} catch (Throwable e) {
logger.error("Error in discovery System Services Endpoint in scope: " + scope);
logger.error(e.getLocalizedMessage(), e);
throw e;
}
}
}