Skip to content

Commit

Permalink
add deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
wistefan committed Jan 28, 2025
1 parent 806ba94 commit f784b99
Show file tree
Hide file tree
Showing 22 changed files with 554 additions and 122 deletions.
13 changes: 13 additions & 0 deletions api/rainbow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,19 @@ paths:
description: Bad Request
'404':
description: Not found
delete:
tags:
- agreement
parameters:
- $ref: '#/components/parameters/AgreementId'
operationId: deleteAgreementById
summary: Delete agreement by id
description: Delete the agreement with the given id
responses:
'202':
description: Agreement deleted
'400':
description: Bad Request

components:
parameters:
Expand Down
36 changes: 24 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<tmforum.party.api.url>
https://raw.githubusercontent.com/FIWARE/tmforum-api/refs/heads/main/api/tm-forum/party-catalog/api.json
</tmforum.party.api.url>
<tmforum.agreement.api.url>
https://raw.githubusercontent.com/FIWARE/tmforum-api/refs/heads/main/api/tm-forum/agreement/api.json
</tmforum.agreement.api.url>

<!-- Rainbow API -->
<rainbow.api>${project.basedir}/api/rainbow.yaml</rainbow.api>
Expand Down Expand Up @@ -181,6 +184,13 @@
<scope>runtime</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.18.2</version>
</dependency>

<!-- Tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -325,21 +335,20 @@
</configuration>
</execution>
<execution>
<id>openapi-product-ordering-api-client</id>
<id>openapi-product-ordering-api</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${tmforum.productorder.api.url}</inputSpec>
<apiPackage>org.fiware.iam.tmforum.productorder.api</apiPackage>
<strictSpec>true</strictSpec>
<modelPackage>org.fiware.iam.tmforum.productorder.model</modelPackage>
<apiPackage>org.fiware.iam.tmforum.productorder.api</apiPackage>
<generatorName>micronaut</generatorName>
<modelNameSuffix>VO</modelNameSuffix>
<output>${project.build.directory}</output>
<generateSupportingFiles>false</generateSupportingFiles>
<apisToGenerate>EventsSubscription</apisToGenerate>
<configOptions>
<clientId>product-order</clientId>
<fullJavaUtil>true</fullJavaUtil>
Expand All @@ -348,38 +357,39 @@
<useLombokGenerated>true</useLombokGenerated>
<introspected>true</introspected>
<useBeanValidation>false</useBeanValidation>
<supportAsync>false</supportAsync>
<supportAsync>true</supportAsync>
<jacksonDatabindNullable>false</jacksonDatabindNullable>
<generateExamples>true</generateExamples>
</configOptions>
<typeMappings>
<typeMapping>java.util.Date=java.time.Instant</typeMapping>
</typeMappings>
</configuration>
</execution>
<execution>
<id>openapi-product-ordering-api</id>
<id>openapi-agreement-api</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${tmforum.productorder.api.url}</inputSpec>
<inputSpec>${tmforum.agreement.api.url}</inputSpec>
<strictSpec>true</strictSpec>
<modelPackage>org.fiware.iam.tmforum.productorder.model</modelPackage>
<modelPackage>org.fiware.iam.tmforum.agreement.model</modelPackage>
<apiPackage>org.fiware.iam.tmforum.agreement.api</apiPackage>
<generateAliasAsModel>true</generateAliasAsModel>
<generatorName>micronaut</generatorName>
<modelNameSuffix>VO</modelNameSuffix>
<modelNameSuffix>TmfVO</modelNameSuffix>
<output>${project.build.directory}</output>
<generateSupportingFiles>false</generateSupportingFiles>
<generateApis>false</generateApis>
<generateApiTests>false</generateApiTests>
<generateModels>true</generateModels>
<configOptions>
<clientId>tmforum-agreement-api</clientId>
<fullJavaUtil>true</fullJavaUtil>
<useOptional>false</useOptional>
<useGenericResponse>true</useGenericResponse>
<useLombokGenerated>true</useLombokGenerated>
<introspected>true</introspected>
<useBeanValidation>false</useBeanValidation>
<supportAsync>true</supportAsync>
<jacksonDatabindNullable>false</jacksonDatabindNullable>
</configOptions>
<typeMappings>
Expand Down Expand Up @@ -778,6 +788,8 @@
<portBinding>8083:8083</portBinding>
<!-- trusted-issuers-list -->
<portBinding>8085:8085</portBinding>
<!-- tm-forum-api-agreement -->
<portBinding>8086:8086</portBinding>
<!-- orion -->
<portBinding>1026:1026</portBinding>
<!-- rainbow -->
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/fiware/iam/Application.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.fiware.iam;

import io.micronaut.context.annotation.Factory;
import io.micronaut.runtime.Micronaut;

@Factory
public class Application {

public static void main(String[] args) {
Micronaut.run(Application.class, args);
}

}
9 changes: 3 additions & 6 deletions src/main/java/org/fiware/iam/RainbowMapper.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.fiware.iam;

import org.fiware.iam.tmforum.productcatalog.model.CatalogVO;
import org.fiware.iam.tmforum.productcatalog.model.ProductSpecificationVO;
import org.fiware.iam.tmforum.productcatalog.model.RelatedPartyVO;
import org.fiware.rainbow.model.NewCatalogVO;
import org.fiware.rainbow.model.NewDataserviceVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;
import java.util.Optional;

/**
* Mapper for objects used in the Rainbow API
*/
@Mapper(componentModel = "jsr330")
public interface RainbowMapper {

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/fiware/iam/TMFMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.fiware.iam;

import org.fiware.iam.tmforum.agreement.model.RelatedPartyTmfVO;
import org.fiware.iam.tmforum.productorder.model.RelatedPartyVO;
import org.mapstruct.Mapper;
/**
* Mapper for objects between TMForum APIs
*/
@Mapper(componentModel = "jsr330")
public interface TMFMapper {

RelatedPartyTmfVO map(RelatedPartyVO relatedPartyVO);
}
56 changes: 56 additions & 0 deletions src/main/java/org/fiware/iam/dsp/RainbowAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.fiware.iam.dsp;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import jakarta.inject.Singleton;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.fiware.iam.exception.RainbowException;
import org.fiware.rainbow.api.AgreementApiClient;
import org.fiware.rainbow.model.AgreementCreateVO;
import org.fiware.rainbow.model.AgreementVO;
import reactor.core.publisher.Mono;


/**
* Adapter to handle communication with Rainbow.
*/
@Singleton
@RequiredArgsConstructor
@Slf4j
public class RainbowAdapter {

private final AgreementApiClient agreementApiClient;
private final ObjectMapper objectMapper;

/**
* Create the agreement for the given organization and offer
*/
public Mono<AgreementVO> createAgreement(String organizationId, String offeringId) {
AgreementCreateVO agreementCreateVO = new AgreementCreateVO()
.identity(organizationId)
.dataServiceId(offeringId);

return agreementApiClient
.createAgreement(agreementCreateVO)
.onErrorMap(t -> new RainbowException("Was not able to create agreement"))
.map(HttpResponse::body)
.map(body -> objectMapper.convertValue(body, AgreementVO.class));
}

/**
* Delete the agreement with the given id
*/
public Mono<Boolean> deleteAgreement(String agreementId) {
return agreementApiClient.deleteAgreementById(agreementId)
.map(objectHttpResponse -> {
if (objectHttpResponse.status().equals(HttpStatus.ACCEPTED)) {
return true;
}
return false;
})
.onErrorReturn(false);
}

}
15 changes: 15 additions & 0 deletions src/main/java/org/fiware/iam/exception/RainbowException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.fiware.iam.exception;

/**
* Exception to be thrown in case of problems with rainbow
*/
public class RainbowException extends RuntimeException {

public RainbowException(String message) {
super(message);
}

public RainbowException(String message, Throwable cause) {
super(message, cause);
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/fiware/iam/exception/TMForumException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.fiware.iam.exception;

/**
* Exception to be thrown in case of issues with the tmforum api
*/
public class TMForumException extends RuntimeException{
public TMForumException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.fiware.iam.exception;

/**
* Exception to be thrown in case of issues with the trusted-issuers-list
*/
public class TrustedIssuersException extends RuntimeException {

public TrustedIssuersException(String message) {
super(message);
}

public TrustedIssuersException(String message, Throwable cause) {
super(message, cause);
}
}
32 changes: 23 additions & 9 deletions src/main/java/org/fiware/iam/til/TrustedIssuersListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.fiware.iam.exception.TMForumException;
import org.fiware.iam.exception.TrustedIssuersException;
import org.fiware.iam.til.api.IssuerApiClient;
import org.fiware.iam.til.model.ClaimVO;
import org.fiware.iam.til.model.CredentialsVO;
import org.fiware.iam.til.model.TrustedIssuerVO;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Optional;
import java.util.*;

@Singleton
@RequiredArgsConstructor
Expand All @@ -34,26 +34,40 @@ public Mono<?> allowIssuer(String issuerDid) {
log.debug("Requested issuer {} does not exist.", issuerDid);
return Mono.just(Optional.empty());
}
throw new TMForumException("Client error on issuer retrieval.", e);
throw new TrustedIssuersException("Client error on issuer retrieval.", e);
})
.flatMap(optionalIssuer -> {
if (optionalIssuer.isPresent()) {
TrustedIssuerVO updatedIssuer = optionalIssuer.get().addCredentialsItem(credentialToBeAdded);
log.debug("Updating existing issuer with {}", updatedIssuer);
return apiClient.updateIssuer(issuerDid, updatedIssuer);
CredentialsVO cvo = optionalIssuer.get().getCredentials()
.stream()
.filter(credentialsVO -> credentialsVO.getCredentialsType().equals(credentialToBeAdded.getCredentialsType()))
.findAny()
.orElse(credentialToBeAdded);
TrustedIssuerVO trustedIssuerVO = optionalIssuer.get();

// convert to set, to prevent duplicates
Set<ClaimVO> claimSet = new HashSet<>(cvo.getClaims());
claimSet.addAll(credentialToBeAdded.getClaims());
cvo.claims(new ArrayList<>(claimSet));

Set<CredentialsVO> credentialsVOSet = new HashSet<>(trustedIssuerVO.getCredentials());
credentialsVOSet.add(cvo);
trustedIssuerVO.setCredentials(new ArrayList<>(credentialsVOSet));
log.debug("Updating existing issuer with {}", trustedIssuerVO);
return apiClient.updateIssuer(issuerDid, trustedIssuerVO);
} else {
TrustedIssuerVO newIssuer = new TrustedIssuerVO().did(issuerDid).addCredentialsItem(credentialToBeAdded);
log.debug("Adding new issuer with {}", newIssuer);
return apiClient.createTrustedIssuer(newIssuer);
}
})
.onErrorMap(e -> {
throw new TMForumException("Was not able to allow the issuer.", e);
throw new TrustedIssuersException("Was not able to allow the issuer.", e);
});

}

public Mono<?> denyIssuer(String issuerDid) {
public Mono<HttpResponse<?>> denyIssuer(String issuerDid) {
CredentialsVO credentialToBeRemoved = trustedIssuerConfigProvider.createCredentialConfigForTargetService();

return getIssuer(issuerDid)
Expand All @@ -70,7 +84,7 @@ public Mono<?> denyIssuer(String issuerDid) {
return Mono.just(HttpResponse.noContent());
})
.onErrorMap(e -> {
throw new TMForumException("Was not able to deny the issuer.", e);
throw new TrustedIssuersException("Was not able to deny the issuer.", e);
});

}
Expand Down
Loading

0 comments on commit f784b99

Please sign in to comment.