catalogue-util-library/src/main/java/org/gcube/datacatalogue/utillibrary/server/utils/GCubeUtils.java

62 lines
1.6 KiB
Java

package org.gcube.datacatalogue.utillibrary.server.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class GCubeUtils.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Feb 10, 2021
*/
public class GCubeUtils {
/**
* The Enum GCUBE_SCOPE_LEVEL.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Feb 10, 2021
*/
public static enum GCUBE_SCOPE_LEVEL {
ROOT, VO, VRE
}
private static final Logger LOG = LoggerFactory.getLogger(CatalogueUtilMethods.class);
/**
* To G cube level.
*
* @param scope the scope
* @return the gcube scope level
* @throws IllegalArgumentException the illegal argument exception
*/
public static GCUBE_SCOPE_LEVEL toGCubeLevel(String scope) throws IllegalArgumentException {
LOG.debug("called toGCubeLevel on " + scope);
if (scope == null || scope.isEmpty())
throw new IllegalArgumentException("Scope is null or empty");
if (!scope.startsWith("/")) {
throw new IllegalArgumentException("Scope should start with '/' ->" + scope);
}
if (scope.endsWith("/")) {
throw new IllegalArgumentException("Scope should not end with '/' ->" + scope);
}
String[] splits = scope.split("/");
if (splits.length > 4)
throw new IllegalArgumentException("Scope is invalid, too many '/' ->" + scope);
if (splits.length == 2) // is a root VO
return GCUBE_SCOPE_LEVEL.ROOT;
else if (splits.length == 3) {// is a VO
return GCUBE_SCOPE_LEVEL.VO;
} else if (splits.length == 4) {// is a VRE
return GCUBE_SCOPE_LEVEL.VRE;
}
return null;
}
}