Skip to content
Closed
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
24 changes: 22 additions & 2 deletions api/tm-forum/product-inventory/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,11 @@
"format": "date-time",
"description": "Is the date when the product was terminated"
},
"lastUpdate": {
"type": "string",
"format": "date-time",
"description": "Date and time of the last update"
},
"agreement": {
"type": "array",
"items": {
Expand Down Expand Up @@ -1366,7 +1371,7 @@
},
"Product_Create": {
"type": "object",
"description": "A product offering procured by a customer or other interested party playing a party role. A product is realized as one or more service(s) and / or resource(s).\nSkipped properties: id,href",
"description": "A product offering procured by a customer or other interested party playing a party role. A product is realized as one or more service(s) and / or resource(s).\nSkipped properties: id,href,lastUpdate",
"required": [
"status"
],
Expand Down Expand Up @@ -1406,6 +1411,11 @@
"format": "date-time",
"description": "Is the date when the product was terminated"
},
"lastUpdate": {
"type": "string",
"format": "date-time",
"description": "Date and time of the last update"
},
"agreement": {
"type": "array",
"items": {
Expand Down Expand Up @@ -1502,7 +1512,7 @@
},
"Product_Update": {
"type": "object",
"description": "A product offering procured by a customer or other interested party playing a party role. A product is realized as one or more service(s) and / or resource(s).\nSkipped properties: id,href",
"description": "A product offering procured by a customer or other interested party playing a party role. A product is realized as one or more service(s) and / or resource(s).\nSkipped properties: id,href,lastUpdate",
"properties": {
"description": {
"type": "string",
Expand Down Expand Up @@ -1539,6 +1549,11 @@
"format": "date-time",
"description": "Is the date when the product was terminated"
},
"lastUpdate": {
"type": "string",
"format": "date-time",
"description": "Date and time of the last update"
},
"agreement": {
"type": "array",
"items": {
Expand Down Expand Up @@ -1851,6 +1866,11 @@
"format": "date-time",
"description": "Is the date when the product was terminated"
},
"lastUpdate": {
"type": "string",
"format": "date-time",
"description": "Date and time of the last update"
},
"agreement": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public void serialize(T objectToSerialize, JsonGenerator jsonGenerator, Serializ
fieldsToInclude.addAll(Arrays.asList(optionalFieldsParameter.get().split(FIELD_PARAMETER_SEPERATOR)));
fieldsToInclude.addAll(MANDATORY_FIELDS);

// If lastUpdate field exists and is not null, always include it
if (objectNode.has("lastUpdate") && !objectNode.get("lastUpdate").isNull()) {
fieldsToInclude.add("lastUpdate");
}

Iterator<String> fieldNameIterator = jsonNode.fieldNames();

List<String> fieldsToRemove = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ private static Stream<Arguments> provideFieldParameters() {
Arguments.of("Only name and the mandatory parameters should have been included.", "name",
CustomerBillOnDemandVOTestExample.build().atSchemaLocation(null)
.description(null)
.lastUpdate(null)
.lastUpdate(Instant.MAX.toString())
.state(null)
.relatedParty(null)
.customerBill(null)
Expand All @@ -409,7 +409,7 @@ private static Stream<Arguments> provideFieldParameters() {
"Only the mandatory parameters should have been included when a non-existent field was requested.",
"nothingToSeeHere", CustomerBillOnDemandVOTestExample.build().atSchemaLocation(null)
.description(null)
.lastUpdate(null)
.lastUpdate(Instant.MAX.toString())
.state(null)
.name(null)
.relatedParty(null)
Expand All @@ -420,7 +420,7 @@ private static Stream<Arguments> provideFieldParameters() {
.atSchemaLocation(null)),
Arguments.of("Only name, state, description and the mandatory parameters should have been included.",
"name,state,description", CustomerBillOnDemandVOTestExample.build().atSchemaLocation(null)
.lastUpdate(null)
.lastUpdate(Instant.MAX.toString())
.relatedParty(null)
.customerBill(null)
.billingAccount(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@
import org.fiware.tmforum.productinventory.TMForumMapper;
import reactor.core.publisher.Mono;

import java.time.Clock;
import java.util.*;

@Slf4j
@Controller("${general.basepath:/}")
public class ProductApiController extends AbstractApiController<Product> implements ProductApi {

private final TMForumMapper tmForumMapper;
private final Clock clock;

public ProductApiController(QueryParser queryParser, ReferenceValidationService validationService,
TmForumRepository repository, TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) {
TmForumRepository repository, TMForumMapper tmForumMapper, Clock clock, TMForumEventHandler eventHandler) {
super(queryParser, validationService, repository, eventHandler);
this.tmForumMapper = tmForumMapper;
this.clock = clock;
}

@Override
Expand All @@ -43,6 +46,8 @@ public Mono<HttpResponse<ProductVO>> createProduct(@NonNull ProductCreateVO prod
tmForumMapper.map(productCreateVO,
IdHelper.toNgsiLd(UUID.randomUUID().toString(), Product.TYPE_PRODUCT)));

product.setLastUpdate(clock.instant());

return create(getCheckingMono(product), Product.class)
.map(tmForumMapper::map)
.map(HttpResponse::created);
Expand Down Expand Up @@ -133,6 +138,7 @@ private Mono<Product> getCheckingMono(Product product) {
}

Product product = tmForumMapper.map(productUpdateVO, id);
product.setLastUpdate(clock.instant());

return patch(id, product, getCheckingMono(product), Product.class)
.map(tmForumMapper::map)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public void createProduct201() throws Exception {
() -> productApiTestClient.createProduct(null, productCreateVO));
assertEquals(HttpStatus.CREATED, productVOHttpResponse.getStatus(), message);
String rfId = productVOHttpResponse.body().getId();
Instant lastUpdate = productVOHttpResponse.body().getLastUpdate();
expectedProduct.setId(rfId);
expectedProduct.setHref(rfId);
expectedProduct.setLastUpdate(lastUpdate);

assertEquals(expectedProduct, productVOHttpResponse.body(), message);
}
Expand Down Expand Up @@ -523,12 +525,14 @@ public void listProduct200() throws Exception {
.productSpecification(null)
.billingAccount(null)
.productOffering(null);
String id = productApiTestClient.createProduct(null, productCreateVO)
.body().getId();
ProductVO body = productApiTestClient.createProduct(null, productCreateVO).body();
String id = body.getId();
Instant lastUpdate = body.getLastUpdate();
ProductVO productVO = ProductVOTestExample.build().atSchemaLocation(null);
productVO
.id(id)
.href(id)
.lastUpdate(lastUpdate)
.productSpecification(null)
.billingAccount(null)
.productOffering(null)
Expand Down Expand Up @@ -682,7 +686,8 @@ public void patchProduct200() throws Exception {
assertEquals(HttpStatus.OK, updateResponse.getStatus(), message);

ProductVO updatedProduct = updateResponse.body();
expectedProduct.href(productId).id(productId);
Instant lastUpdate = updatedProduct.getLastUpdate();
expectedProduct.href(productId).id(productId).lastUpdate(lastUpdate);

assertEquals(expectedProduct, updatedProduct, message);
}
Expand Down Expand Up @@ -1211,6 +1216,7 @@ public void retrieveProduct200(String message, String fields, ProductVO expected
this.fieldsParameter = fields;
this.message = message;
this.expectedProduct = expectedProduct;

retrieveProduct200();
}

Expand All @@ -1225,15 +1231,20 @@ public void retrieveProduct200() throws Exception {
() -> productApiTestClient.createProduct(null, productCreateVO));
assertEquals(HttpStatus.CREATED, createResponse.getStatus(), message);
String id = createResponse.body().getId();
Instant lastUpdate = createResponse.body().getLastUpdate();

expectedProduct
.id(id)
.href(id);
.href(id)
.lastUpdate(lastUpdate);


//then retrieve
HttpResponse<ProductVO> retrievedRF = callAndCatch(
() -> productApiTestClient.retrieveProduct(null, id, fieldsParameter));
assertEquals(HttpStatus.OK, retrievedRF.getStatus(), message);

//retrievedRF.body().setLastUpdate(lastUpdate);
assertEquals(expectedProduct, retrievedRF.body(), message);
}

Expand All @@ -1250,6 +1261,7 @@ private static Stream<Arguments> provideFieldParameters() {
.productOrderItem(null)
.realizingResource(null)
.realizingService(null)
//.lastUpdate(Instant.MAX)
.relatedParty(null)),
Arguments.of("Only description and the mandatory parameters should have been included.", "description",
ProductVOTestExample.build().atSchemaLocation(null)
Expand Down Expand Up @@ -1307,7 +1319,7 @@ private static Stream<Arguments> provideFieldParameters() {
.atBaseType(null)
.atType(null)
.atSchemaLocation(null)),
Arguments.of("Only description, isBundle and the mandatory parameters should have been included.",
Arguments.of("Only description, lastUpdate, isBundle and the mandatory parameters should have been included.",
"description,isBundle", ProductVOTestExample.build().atSchemaLocation(null)
.isCustomerVisible(null)
.name(null)
Expand All @@ -1333,6 +1345,7 @@ private static Stream<Arguments> provideFieldParameters() {
.atBaseType(null)
.atType(null)
.atSchemaLocation(null)));

}

@Disabled("400 cannot happen, only 404")
Expand Down Expand Up @@ -1390,4 +1403,4 @@ public void retrieveProduct500() throws Exception {
protected String getEntityType() {
return Product.TYPE_PRODUCT;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class Product extends EntityWithId {
@Setter(onMethod = @__({ @AttributeSetter(value = AttributeType.PROPERTY, targetName = "terminationDate") }))
private Instant terminationDate;

@Getter(onMethod = @__({ @AttributeGetter(value = AttributeType.PROPERTY, targetName = "lastUpdate") }))
@Setter(onMethod = @__({ @AttributeSetter(value = AttributeType.PROPERTY, targetName = "lastUpdate") }))
private Instant lastUpdate;

@Getter(onMethod = @__({
@AttributeGetter(value = AttributeType.RELATIONSHIP_LIST, targetName = "agreement", embedProperty = true) }))
@Setter(onMethod = @__({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ private static Stream<Arguments> provideFieldParameters() {
ServiceSpecificationVOTestExample.build().atSchemaLocation(null)
.description(null)
.isBundle(null)
.lastUpdate(null)
.lastUpdate(Instant.MAX)
.lifecycleStatus(null)
.name(null)
.attachment(null)
Expand All @@ -1023,7 +1023,7 @@ private static Stream<Arguments> provideFieldParameters() {
"nothingToSeeHere", ServiceSpecificationVOTestExample.build().atSchemaLocation(null)
.description(null)
.isBundle(null)
.lastUpdate(null)
.lastUpdate(Instant.MAX)
.lifecycleStatus(null)
.name(null)
.version(null)
Expand Down
Loading