332 lines
10 KiB
Java
332 lines
10 KiB
Java
package org.gcube.application;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
|
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
|
|
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
|
|
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.ActionDefinitionDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV;
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
/**
|
|
* The Class UCD_Tests.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
*
|
|
* Sep 9, 2022
|
|
*/
|
|
public class UCD_Tests {
|
|
|
|
private UseCaseDescriptorCaller client = null;
|
|
|
|
// private static String CONTEXT = "/pred4s/preprod/preVRE";
|
|
// private static String TOKEN = ""; //preVRE
|
|
|
|
private static String CONTEXT = "/gcube/devsec/devVRE";
|
|
private static String TOKEN = ""; // devVRE
|
|
|
|
private static String PROFILE_ID = "profiledConcessioni";
|
|
|
|
/**
|
|
* Gets the client.
|
|
*
|
|
* @return the client
|
|
*/
|
|
@Before
|
|
public void getClient() {
|
|
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
client = GeoportalClientCaller.useCaseDescriptors();
|
|
}
|
|
|
|
/**
|
|
* Gets the list.
|
|
*
|
|
* @return the list
|
|
* @throws Exception the exception
|
|
*/
|
|
@Test
|
|
public void getList() throws Exception {
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
List<UseCaseDescriptor> listOfUCD = client.getList();
|
|
|
|
int i = 0;
|
|
for (UseCaseDescriptor useCaseDescriptor : listOfUCD) {
|
|
System.out.println(++i + ") " + useCaseDescriptor);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets the item by ID.
|
|
*
|
|
* @return the item by ID
|
|
* @throws Exception the exception
|
|
*/
|
|
// @Test
|
|
public void getItemByID() throws Exception {
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
UseCaseDescriptor ucd = client.getUCDForId(PROFILE_ID);
|
|
System.out.println(ucd);
|
|
}
|
|
|
|
/**
|
|
* Convert to DV object.
|
|
*
|
|
* @throws Exception the exception
|
|
*/
|
|
// @Test
|
|
public void convertToDVObject() throws Exception {
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
List<UseCaseDescriptor> listOfUCD = client.getList();
|
|
|
|
int i = 0;
|
|
for (UseCaseDescriptor useCaseDescriptor : listOfUCD) {
|
|
System.out.println(++i + ") " + useCaseDescriptor);
|
|
ConvertToDataValueObjectModel.toUseCaseDescriptorDV(useCaseDescriptor, null);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets the UCD for data entry handler ids.
|
|
*
|
|
* @return the UCD for data entry handler ids
|
|
* @throws Exception the exception
|
|
*/
|
|
//@Test
|
|
public void getUCDFor_DataEntry_HandlerIds() throws Exception {
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
List<String> handlersIds = null;
|
|
List<UseCaseDescriptor> listUseCaseDescriptor;
|
|
try {
|
|
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
|
|
|
|
if (handlersIds == null) {
|
|
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
|
|
System.out.println("handlersIds is null, so using default: " + handlersIds);
|
|
}
|
|
listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
|
|
} catch (Exception e) {
|
|
String error = "Error on contacting the Geoportal service";
|
|
System.out.println(error + " for handlers: " + handlersIds);
|
|
throw new Exception(
|
|
"Error when contacting the Geoportal service. Refresh and try again or contact the support", e);
|
|
}
|
|
|
|
if (listUseCaseDescriptor == null) {
|
|
listUseCaseDescriptor = new ArrayList<UseCaseDescriptor>();
|
|
}
|
|
|
|
List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>(listUseCaseDescriptor.size());
|
|
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
|
|
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
|
|
}
|
|
|
|
for (UseCaseDescriptorDV useCaseDescriptorDV : listUCDDV) {
|
|
System.out.println("Found: " + useCaseDescriptorDV);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Gets the UCD for data list handler ids.
|
|
*
|
|
* @return the UCD for data list handler ids
|
|
* @throws Exception the exception
|
|
*/
|
|
//@Test
|
|
public void getUCDFor_DataList_HandlerIds() throws Exception {
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
List<String> handlersIds = null;
|
|
List<UseCaseDescriptor> listUseCaseDescriptor;
|
|
try {
|
|
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
|
|
|
|
if (handlersIds == null) {
|
|
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_list.getId());
|
|
System.out.println("handlersIds is null, so using default: " + handlersIds);
|
|
}
|
|
listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
|
|
} catch (Exception e) {
|
|
String error = "Error on contacting the Geoportal service";
|
|
System.out.println(error + " for handlers: " + handlersIds);
|
|
throw new Exception(
|
|
"Error when contacting the Geoportal service. Refresh and try again or contact the support", e);
|
|
}
|
|
|
|
if (listUseCaseDescriptor == null) {
|
|
listUseCaseDescriptor = new ArrayList<UseCaseDescriptor>();
|
|
}
|
|
|
|
List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>(listUseCaseDescriptor.size());
|
|
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
|
|
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
|
|
}
|
|
|
|
System.out.println(listUCDDV);
|
|
|
|
}
|
|
|
|
/**
|
|
* Gets the configurations for UC D data handlers.
|
|
*
|
|
* @return the configurations for UC D data handlers
|
|
* @throws Exception the exception
|
|
*/
|
|
//@Test
|
|
public void getConfigurations_ForUCD_Data_Handlers() throws Exception {
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
List<String> handlersIds = null;
|
|
List<UseCaseDescriptor> listUseCaseDescriptor;
|
|
try {
|
|
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
|
|
|
|
if (handlersIds == null) {
|
|
//handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_list.getId(), GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
|
|
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_workflow_action_list.getId());
|
|
System.out.println("handlersIds is null, so using default: " + handlersIds);
|
|
}
|
|
listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
|
|
} catch (Exception e) {
|
|
String error = "Error on contacting the Geoportal service";
|
|
System.out.println(error + " for handlers: " + handlersIds);
|
|
throw new Exception(
|
|
"Error when contacting the Geoportal service. Refresh and try again or contact the support", e);
|
|
}
|
|
|
|
if (listUseCaseDescriptor == null) {
|
|
listUseCaseDescriptor = new ArrayList<UseCaseDescriptor>();
|
|
}
|
|
|
|
List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>(listUseCaseDescriptor.size());
|
|
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
|
|
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
|
|
}
|
|
|
|
for (UseCaseDescriptorDV useCaseDescriptorDV : listUCDDV) {
|
|
System.out.println("\n");
|
|
System.out.println("UCD name:" + useCaseDescriptorDV.getName());
|
|
System.out.println("UCD profileID:" + useCaseDescriptorDV.getProfileID());
|
|
List<HandlerDeclarationDV> handlers = useCaseDescriptorDV.getHandlers();
|
|
for (HandlerDeclarationDV handler : handlers) {
|
|
ConfigurationDV<?> config = handler.getConfiguration();
|
|
System.out.println("\tConfig type:" + config.getConfigurationType());
|
|
//System.out.println("\tConfig:" + config.getConfiguration());
|
|
switch (config.getConfigurationType()) {
|
|
case gcube_profiles:
|
|
List<GcubeProfileDV> listProfiles = toListGcubeProfiles(config);
|
|
System.out.println("\t\t"+listProfiles);
|
|
break;
|
|
case item_fields:
|
|
List<ItemFieldDV> listItems = toListItemFields(config);
|
|
System.out.println("\t\t"+listItems);
|
|
break;
|
|
case actions_definition:
|
|
List<ActionDefinitionDV> listActions = toListActionsDefinition(config);
|
|
System.out.println("\t\t"+listActions);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
System.out.println("\n\n");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Registrer file sets.
|
|
*
|
|
* @throws Exception the exception
|
|
*/
|
|
// @Test
|
|
public void registrerFileSets() throws Exception {
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
// FileSets.build(TOKEN, PROFILE_ID, CONTEXT)
|
|
|
|
// System.out.println(listUCDDV);
|
|
|
|
}
|
|
|
|
/**
|
|
* To list gcube profiles.
|
|
*
|
|
* @param config the config
|
|
* @return the list
|
|
*/
|
|
private List<GcubeProfileDV> toListGcubeProfiles(ConfigurationDV<?> config) {
|
|
|
|
try {
|
|
return (List<GcubeProfileDV>) config.getConfiguration();
|
|
} catch (Exception e) {
|
|
System.err.println("Error on casting " + ConfigurationDV.class.getName() + " to List of "
|
|
+ GcubeProfileDV.class.getName());
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
/**
|
|
* To list actions definition.
|
|
*
|
|
* @param config the config
|
|
* @return the list
|
|
*/
|
|
private List<ActionDefinitionDV> toListActionsDefinition(ConfigurationDV<?> config) {
|
|
|
|
try {
|
|
return (List<ActionDefinitionDV>) config.getConfiguration();
|
|
} catch (Exception e) {
|
|
System.err.println("Error on casting " + ConfigurationDV.class.getName() + " to List of "
|
|
+ ActionDefinitionDV.class.getName());
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* To list item fields.
|
|
*
|
|
* @param config the config
|
|
* @return the list
|
|
*/
|
|
private List<ItemFieldDV> toListItemFields(ConfigurationDV<?> config) {
|
|
|
|
try {
|
|
return (List<ItemFieldDV>) config.getConfiguration();
|
|
} catch (Exception e) {
|
|
System.err.println("Error on casting " + ConfigurationDV.class.getName() + " to List of "
|
|
+ ItemFieldDV.class.getName());
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
}
|