Migrating code to take advantage of using Encrypted class

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/is-exporter-se-plugin@176996 82a268e6-3cf1-43bd-a215-b396298e98cf
model-reorganization
Luca Frosini 5 years ago
parent 3fba3f4b85
commit 37a4cc41cd

@ -11,12 +11,14 @@ import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.relation.ConsistsOfImpl;
import org.gcube.informationsystem.model.impl.relation.IsIdentifiedByImpl;
import org.gcube.informationsystem.model.impl.utils.ISMapper;
import org.gcube.informationsystem.model.reference.entity.Facet;
import org.gcube.informationsystem.model.reference.entity.Resource;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relation.ConsistsOf;
import org.gcube.informationsystem.model.reference.relation.IsIdentifiedBy;
@ -26,13 +28,11 @@ import org.gcube.resourcemanagement.model.impl.entity.facet.AccessPointFacetImpl
import org.gcube.resourcemanagement.model.impl.entity.facet.NetworkingFacetImpl;
import org.gcube.resourcemanagement.model.impl.entity.facet.ServiceStateFacetImpl;
import org.gcube.resourcemanagement.model.impl.entity.facet.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entity.properties.ValueSchemaImpl;
import org.gcube.resourcemanagement.model.impl.entity.resource.EServiceImpl;
import org.gcube.resourcemanagement.model.reference.entity.facet.AccessPointFacet;
import org.gcube.resourcemanagement.model.reference.entity.facet.NetworkingFacet;
import org.gcube.resourcemanagement.model.reference.entity.facet.ServiceStateFacet;
import org.gcube.resourcemanagement.model.reference.entity.facet.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entity.properties.ValueSchema;
import org.gcube.resourcemanagement.model.reference.entity.resource.EService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -53,22 +53,15 @@ public class ServiceEndpointExporter extends GCoreResourceMapper<ServiceEndpoint
public static final String USERNAME = "USERNAME";
public static final String PASSWORD = "PASSWORD";
public static final String USERNAME_PASSWORD_SCHEMA_STRING;
public static final String NAME = "name";
public static final String VALUE = "value";
public static final String ENCRYPTED = "encrypted";
public static final String ARRAY = "ARRAY";
public static final String PROPERTIES = "PROPERTIES";
public static final String NOT_URI_ENDPOINT = "NOT_URI_ENDPOINT";
static {
USERNAME_PASSWORD_SCHEMA_STRING = String.format("%s:%s", USERNAME, PASSWORD);
}
public ServiceEndpointExporter(boolean filteredReport){
super(ServiceEndpoint.class, EService.class, filteredReport);
}
@ -238,59 +231,48 @@ public class ServiceEndpointExporter extends GCoreResourceMapper<ServiceEndpoint
accessPointFacets[i].setDescription(getStringAsUTF8(accessPointDescription));
}
/* ---------- */
ValueSchema authorization = new ValueSchemaImpl();
String value = USERNAME_PASSWORD_SCHEMA_STRING;
String schema = USERNAME_PASSWORD_SCHEMA_STRING;
boolean replaceColon = false;
try {
value = value.replace(USERNAME, accessPoint.username());
}catch (NullPointerException e) {
value = value.replace(USERNAME, "");
schema = schema.replace(USERNAME, "");
replaceColon = true;
}
/* Managing Username and Password */
try {
value = value.replace(PASSWORD, accessPoint.password());
String username = accessPoint.username();
String passwordString = accessPoint.password();
Encrypted password = new EncryptedImpl();
password.setEncryptedValue(passwordString);
accessPointFacets[i].setAdditionalProperty(USERNAME, username);
accessPointFacets[i].setAdditionalProperty(PASSWORD, password);
}catch (NullPointerException e) {
value = value.replace(PASSWORD, "");
schema = schema.replace(PASSWORD, "");
replaceColon = true;
}
if(replaceColon){
value = value.replace(":", "");
schema = schema.replace(":", "");
}
/* END Managing Username and Password */
if(value.compareTo("")!=0){
authorization.setValue(value);
authorization.setType(URI.create(schema));
accessPointFacets[i].setAuthorization(authorization);
}
/* ----- */
/* Managing AccessPoint Properties */
Group<Property> properties = accessPoint.properties();
if(properties!=null && properties.size()>0){
ObjectNode propertiesObjectNode = ISMapper.getObjectMapper().createObjectNode();
/*
* List/Set support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354
*/
// This is a workaround
ArrayNode arrayNode = propertiesObjectNode.putArray(ARRAY);
for(Property property : properties){
ObjectNode objectNode = ISMapper.getObjectMapper().createObjectNode();
objectNode.put(NAME, property.name());
objectNode.put(VALUE, property.value());
objectNode.put(ENCRYPTED, Boolean.toString(property.isEncrypted()));
boolean encryptedValue = property.isEncrypted();
if(encryptedValue) {
Encrypted encrypted = new EncryptedImpl();
encrypted.setEncryptedValue(property.value());
objectNode.put(VALUE, encryptedValue);
}else {
objectNode.put(VALUE, property.value());
}
arrayNode.add(objectNode);
}
accessPointFacets[i].setAdditionalProperty(PROPERTIES, propertiesObjectNode);
}
/* END Managing AccessPoint Properties */
i++;
}

Loading…
Cancel
Save