Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making rewritten URIs include some type info. This is a precondition … #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public void setUp() {
componentCatalogUri = env.getProperty("component.catalogUri");
componentModelVersion = env.getProperty("component.modelversion");
sslCertificatePath = env.getProperty("ssl.certificatePath");
elasticsearchHostname = env.getProperty("elasticsearch.hostname");
elasticsearchPort = Integer.parseInt(Objects.requireNonNull(env.getProperty("elasticsearch.port")));
keystorePassword = env.getProperty("keystore.password");
keystoreAlias = env.getProperty("keystore.alias");
// componentIdsId = env.getProperty("component.idsid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public URI updated(Resource resource, URI connectorUri) throws IOException, Reje
SelfDescriptionPersistenceAndIndexing.replacedIds = new HashMap<>(); //Clear the map tracking all URIs that were replaced
resource = new Serializer().deserialize( //Parse to Java Class
SelfDescriptionPersistenceAndIndexing.addSameAsStatements( //Add owl:sameAs statements for all URIs we are replacing
SelfDescriptionPersistenceAndIndexing.rewriteResource(resource.toRdf(), resource, catalogUri)), //Replace URIs
//TODO: Here, we assume that an offeredResource is updated, not a requestedResource
SelfDescriptionPersistenceAndIndexing.rewriteResource(resource.toRdf(), resource, catalogUri, true)), //Replace URIs
Resource.class); //Result of parsing should be a Resource
} catch (URISyntaxException e) {
throw new RejectMessageException(RejectionReason.INTERNAL_RECIPIENT_ERROR, e);
Expand Down Expand Up @@ -245,8 +246,8 @@ public String getResults(String queryString) throws RejectMessageException {
* @throws RejectMessageException thrown, if the changes are illegal, or if an internal error has occurred
*/
private void addToTriplestore(Resource resource, URI connectorUri, URI catalogUri) throws IOException, RejectMessageException, URISyntaxException {

ResourceModelCreator.InnerModel result = resourceModelCreator.setConnectorUri(connectorUri).toModel(SelfDescriptionPersistenceAndIndexing.rewriteResource(resource.toRdf(), resource, catalogUri));
//TODO: Here, we assume that an offeredResource is updated, not a requestedResource
ResourceModelCreator.InnerModel result = resourceModelCreator.setConnectorUri(connectorUri).toModel(SelfDescriptionPersistenceAndIndexing.rewriteResource(resource.toRdf(), resource, catalogUri, true));

//Add a statement that this Resource is part of some catalog
//?catalog ids:offeredResource ?resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,62 +141,70 @@ static URI rewriteConnectorUri(URI connectorUri) {
* @return Resource in String representation with rewritten URIs
* @throws URISyntaxException, if malformed URIs are encountered
*/
static String rewriteResource(String currentString, Resource resource, URI catalogUri) throws URISyntaxException {
static String rewriteResource(String currentString, Resource resource, URI catalogUri, boolean isOffer) throws URISyntaxException {
//Was the resource rewritten already?
if(resource.getId().toString().startsWith(componentCatalogUri.toString()))
{
return currentString;
}
URI resourceUri = new URI(catalogUri + "/" + resource.getId().hashCode());
URI resourceUri;
if(isOffer)
{
resourceUri = new URI(catalogUri + "/offeredResource/" + resource.getId().hashCode());
}
else
{
resourceUri = new URI(catalogUri + "/requestedResource/" + resource.getId().hashCode());
}

//First big block is about contracts attached to a resource
if (resource.getContractOffer() != null && !resource.getContractOffer().isEmpty()) {
for (ContractOffer contractOffer : resource.getContractOffer()) {
//Replace original URI of contract offer with a new one, which is in "our domain"
//This allows us to provide further details on this object if requested
URI contractOfferUri = new URI(resourceUri + "/" + contractOffer.getId().hashCode());
URI contractOfferUri = new URI(resourceUri + "/contractOffer/" + contractOffer.getId().hashCode());
currentString = doReplace(currentString, contractOffer.getId(), contractOfferUri);

//There can be a number of different Rules: Obligations/Duties, Prohibitions and Permissions
Map<Rule, URI> allRules = new HashMap<>();
if (contractOffer.getObligation() != null && !contractOffer.getObligation().isEmpty()) {
for (Duty duty : contractOffer.getObligation()) {
allRules.put(duty, new URI(contractOfferUri.toString() + "/" + duty.getId().hashCode()));
allRules.put(duty, new URI(contractOfferUri + "/obligation/" + duty.getId().hashCode()));
}
}
if (contractOffer.getPermission() != null && !contractOffer.getPermission().isEmpty()) {
for (Permission permission : contractOffer.getPermission()) {
allRules.put(permission, new URI(contractOfferUri.toString() + "/" + permission.getId().hashCode()));
allRules.put(permission, new URI(contractOfferUri + "/permission/" + permission.getId().hashCode()));
if (permission.getPreDuty() != null && !permission.getPreDuty().isEmpty()) {
for (Duty duty : permission.getPreDuty()) {
allRules.put(duty, new URI(contractOfferUri.toString() + "/" + permission.getId().hashCode() + "/" + duty.getId().hashCode()));
allRules.put(duty, new URI(contractOfferUri + "/permission/" + permission.getId().hashCode() + "/preDuty/" + duty.getId().hashCode()));
}
}
if (permission.getPostDuty() != null && !permission.getPostDuty().isEmpty()) {
for (Duty duty : permission.getPostDuty()) {
allRules.put(duty, new URI(contractOfferUri.toString() + "/" + permission.getId().hashCode() + "/" + duty.getId().hashCode()));
allRules.put(duty, new URI(contractOfferUri + "/permission/" + permission.getId().hashCode() + "/postDuty/" + duty.getId().hashCode()));
}
}
}
}
if (contractOffer.getProhibition() != null && !contractOffer.getProhibition().isEmpty()) {
for (Prohibition prohibition : contractOffer.getProhibition()) {
allRules.put(prohibition, new URI(contractOfferUri.toString() + "/" + prohibition.getId().hashCode()));
allRules.put(prohibition, new URI(contractOfferUri + "/prohibition/" + prohibition.getId().hashCode()));
}
}
if (!allRules.isEmpty()) {
for (Map.Entry<Rule, URI> ruleEntry : allRules.entrySet()) {
currentString = doReplace(currentString, ruleEntry.getKey().getId(), ruleEntry.getValue());
if (ruleEntry.getKey().getConstraint() != null && !ruleEntry.getKey().getConstraint().isEmpty()) {
for (AbstractConstraint abstractConstraint : ruleEntry.getKey().getConstraint()) {
currentString = doReplace(currentString, abstractConstraint.getId(), new URI(ruleEntry.getValue() + "/" + abstractConstraint.getId().hashCode()));
currentString = doReplace(currentString, abstractConstraint.getId(), new URI(ruleEntry.getValue() + "/constraint/" + abstractConstraint.getId().hashCode()));
}
}
}
}

if (contractOffer.getContractDocument() != null) {
currentString = doReplace(currentString, contractOffer.getContractDocument().getId(), new URI(contractOfferUri + "/" + contractOffer.getContractDocument().getId().hashCode()));
currentString = doReplace(currentString, contractOffer.getContractDocument().getId(), new URI(contractOfferUri + "/contractDocument/" + contractOffer.getContractDocument().getId().hashCode()));
}

}
Expand All @@ -208,9 +216,9 @@ static String rewriteResource(String currentString, Resource resource, URI catal
//Iterate over endpoints. For each present, replace URI
if (resource.getResourceEndpoint() != null && !resource.getResourceEndpoint().isEmpty()) {
for (ConnectorEndpoint connectorEndpoint : resource.getResourceEndpoint()) {
URI endpointUri = new URI(resourceUri + "/" + connectorEndpoint.getId().hashCode());
URI endpointUri = new URI(resourceUri + "/connectorEndpoint/" + connectorEndpoint.getId().hashCode());
if (connectorEndpoint.getEndpointArtifact() != null) {
currentString = doReplace(currentString, connectorEndpoint.getEndpointArtifact().getId(), new URI(endpointUri + "/" + connectorEndpoint.getEndpointArtifact().getId().hashCode()));
currentString = doReplace(currentString, connectorEndpoint.getEndpointArtifact().getId(), new URI(endpointUri + "/endpointArtifact/" + connectorEndpoint.getEndpointArtifact().getId().hashCode()));
}

currentString = doReplace(currentString, connectorEndpoint.getId(), endpointUri);
Expand All @@ -221,11 +229,11 @@ static String rewriteResource(String currentString, Resource resource, URI catal
//Iterate over Representations. If Representation present, adapt string of Representation and, if present, Artifact
if (resource.getRepresentation() != null) {
for (Representation representation : resource.getRepresentation()) {
URI representationURI = new URI(resourceUri + "/" + representation.getId().hashCode());
URI representationURI = new URI(resourceUri + "/representation/" + representation.getId().hashCode());
currentString = doReplace(currentString, representation.getId(), representationURI);
if (representation.getInstance() != null) {
for (RepresentationInstance artifact : representation.getInstance()) {
currentString = doReplace(currentString, artifact.getId(), new URI(representationURI + "/" + artifact.getId().hashCode()));
currentString = doReplace(currentString, artifact.getId(), new URI(representationURI + "/instance/" + artifact.getId().hashCode()));
}
}
}
Expand Down Expand Up @@ -260,18 +268,20 @@ private InfrastructureComponent replaceIds(InfrastructureComponent infrastructur
//If connector is holding catalogs, rewrite them and their contents
if (((Connector) infrastructureComponent).getResourceCatalog() != null) {
for (ResourceCatalog resourceCatalog : ((Connector) infrastructureComponent).getResourceCatalog()) {
URI catalogUri = new URI(infrastructureComponentUri + "/" + resourceCatalog.getId().hashCode());
URI catalogUri = new URI(infrastructureComponentUri + "/resourceCatalog/" + resourceCatalog.getId().hashCode());
currentString = doReplace(currentString, resourceCatalog.getId(), catalogUri);

Set<Resource> resourcesToHandle = new HashSet<>();
if (resourceCatalog.getOfferedResource() != null) {
resourcesToHandle.addAll(resourceCatalog.getOfferedResource());
for(Resource resource : resourceCatalog.getOfferedResource())
{
currentString = rewriteResource(currentString, resource, catalogUri, true);
}
}
if (resourceCatalog.getRequestedResource() != null) {
resourcesToHandle.addAll(resourceCatalog.getRequestedResource());
}
for (Resource currentResource : resourcesToHandle) {
currentString = rewriteResource(currentString, currentResource, catalogUri);
for(Resource resource : resourceCatalog.getRequestedResource())
{
currentString = rewriteResource(currentString, resource, catalogUri, false);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public abstract class MainTemplate implements ComponentInteractorProvider {
public String componentCatalogUri;
public String componentModelVersion;
public String sslCertificatePath;
public String elasticsearchHostname;
public int elasticsearchPort;
public String keystorePassword, keystoreAlias;

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public String getElement(URI requestedElement, int depth, Lang desiredLanguage)
//If the root URI has been requested, we need to create specific SPARQL CONSTRUCT queries to serve a connector catalog
boolean atRoot = false;

if(requestedElement.equals(catalogUri) || (requestedElement.toString() + "/").equals(catalogUri.toString()))
if(requestedElement.equals(catalogUri) || (requestedElement + "/").equals(catalogUri.toString()))
{
logger.info("Catalog has been requested (with depth: " + depth + "): " + requestedElement);
atRoot = true;
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
<spring-boot.version>2.1.16.RELEASE</spring-boot.version>
<jackson.version>2.11.0</jackson.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>4.0.6-SNAPSHOT</revision>
<revision>4.0.9-SNAPSHOT</revision>
</properties>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.1</version>
<version>3.1.2</version>
</plugin>
</plugins>
</reporting>
Expand Down