Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 0f93a90c authored by Szymon Knitter's avatar Szymon Knitter
Browse files

Merge branch 'feature/contractAgreement' into 'develop'

GET ContractAgreement

See merge request !3
parents 096ae52d 93271d32
No related branches found
No related tags found
2 merge requests!10Release 0.0.1,!3GET ContractAgreement
Pipeline #222357 passed with warnings
package eu.simpl.simpl_stubs.controller;
import eu.simpl.simpl_stubs.service.ContractAgreementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/management/v3")
@Slf4j
public class ContractAgreementController {
private final ContractAgreementService contractAgreementService;
public ContractAgreementController(ContractAgreementService contractAgreementService) {
this.contractAgreementService = contractAgreementService;
}
@GetMapping(path = "/contractagreements/{contractAgreementId}", produces = MediaType.APPLICATION_JSON_VALUE)
public Object getContractAgreement(@PathVariable(value = "contractAgreementId") String contractAgreementId) {
log.info("Contract Agreement GET request");
return contractAgreementService.getContractAgreement(contractAgreementId);
}
}
package eu.simpl.simpl_stubs.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
import java.io.IOException;
@Service
public class ContractAgreementService {
@Value("${ca-template-location}")
private String templatePath;
private final ResourceLoader resourceLoader;
public ContractAgreementService(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
public Object getContractAgreement(String contractAgreeementId) {
return getResponseData(templatePath, contractAgreeementId);
}
private Object getResponseData(String filePath, String contractAgreementId) {
Resource resource = this.resourceLoader.getResource(filePath);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
try {
return mapper.readValue(resource.getInputStream(), Object.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
...@@ -2,3 +2,4 @@ spring: ...@@ -2,3 +2,4 @@ spring:
application: application:
name: SIMPL_STUBS name: SIMPL_STUBS
template-location: classpath:templates/sign_response.json template-location: classpath:templates/sign_response.json
ca-template-location: classpath:templates/ca_response.json
{
"@type": "ContractAgreement",
"@id": "b4626ddd-eb35-4d75-8ddf-babd683e1280",
"assetId": "assetId",
"policy": {
"@id": "b4626ddd-eb35-4d75-8ddf-babd683e1280",
"@type": "odrl:Agreement",
"odrl:permission": [],
"odrl:prohibition": [],
"odrl:obligation": [],
"odrl:target": {
"@id": "assetId"
}
},
"contractSigningDate": 1729600269,
"consumerId": "consumer",
"providerId": "provider",
"@context": {
"@vocab": "https://w3id.org/edc/v0.0.1/ns/",
"edc": "https://w3id.org/edc/v0.0.1/ns/",
"odrl": "http://www.w3.org/ns/odrl/2/"
}
}
\ No newline at end of file
package eu.simpl.simpl_stubs.controller;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@SpringBootTest
class ContractAgreementControllerTest {
@Autowired
private ContractAgreementController contractAgreementController;
@Test
void shouldRespondWithAnAnswerWhenGetContractAgreementRequest() {
Object o = contractAgreementController.getContractAgreement("idValue");
assertNotNull(o);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment