Skip to content

Commit 34a9555

Browse files
authored
fix: guard null @type before polymorphic dispatch on create (#162)
1 parent f1c2cca commit 34a9555

4 files changed

Lines changed: 35 additions & 15 deletions

File tree

resource-catalog/src/main/java/org/fiware/tmforum/resourcecatalog/rest/ResourceSpecifcationApiController.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
import io.micronaut.http.annotation.Controller;
88
import lombok.extern.slf4j.Slf4j;
99
import org.fiware.resourcecatalog.api.ResourceSpecificationApi;
10-
import org.fiware.resourcecatalog.model.*;
10+
import org.fiware.resourcecatalog.model.APISpecificationVO;
11+
import org.fiware.resourcecatalog.model.HostingPlatformRequirementSpecificationVO;
12+
import org.fiware.resourcecatalog.model.LogicalResourceSpecificationVO;
13+
import org.fiware.resourcecatalog.model.PhysicalResourceSpecificationVO;
14+
import org.fiware.resourcecatalog.model.ResourceSpecificationCreateVO;
15+
import org.fiware.resourcecatalog.model.ResourceSpecificationUpdateVO;
16+
import org.fiware.resourcecatalog.model.ResourceSpecificationVO;
17+
import org.fiware.resourcecatalog.model.SoftwareResourceSpecificationVO;
18+
import org.fiware.resourcecatalog.model.SoftwareSpecificationVO;
19+
import org.fiware.resourcecatalog.model.SoftwareSupportPackageSpecificationVO;
1120
import org.fiware.tmforum.common.exception.TmForumException;
1221
import org.fiware.tmforum.common.exception.TmForumExceptionReason;
1322
import org.fiware.tmforum.common.mapping.IdHelper;
@@ -17,13 +26,28 @@
1726
import org.fiware.tmforum.common.rest.AbstractApiController;
1827
import org.fiware.tmforum.common.validation.ReferenceValidationService;
1928
import org.fiware.tmforum.common.validation.ReferencedEntity;
20-
import org.fiware.tmforum.resource.*;
29+
import org.fiware.tmforum.resource.ApiSpecification;
30+
import org.fiware.tmforum.resource.FeatureSpecification;
31+
import org.fiware.tmforum.resource.FeatureSpecificationCharacteristicRelationship;
32+
import org.fiware.tmforum.resource.HostingPlatformRequirementSpecification;
33+
import org.fiware.tmforum.resource.LogicalResourceSpecification;
34+
import org.fiware.tmforum.resource.PhysicalResourceSpecification;
35+
import org.fiware.tmforum.resource.ResourceSpecification;
36+
import org.fiware.tmforum.resource.ResourceSpecificationCharacteristic;
37+
import org.fiware.tmforum.resource.ResourceTypeRegistry;
38+
import org.fiware.tmforum.resource.SoftwareResourceSpecification;
39+
import org.fiware.tmforum.resource.SoftwareSpecification;
40+
import org.fiware.tmforum.resource.SoftwareSupportPackageSpecification;
2141
import org.fiware.tmforum.resourcecatalog.TMForumMapper;
2242
import reactor.core.publisher.Mono;
2343

2444
import java.net.URI;
2545
import java.time.Clock;
26-
import java.util.*;
46+
import java.util.ArrayList;
47+
import java.util.List;
48+
import java.util.Map;
49+
import java.util.Optional;
50+
import java.util.UUID;
2751

2852
/**
2953
* REST controller for the ResourceSpecification API within the Resource Catalog module (TMF634).
@@ -73,9 +97,8 @@ public Mono<HttpResponse<ResourceSpecificationVO>> createResourceSpecification(
7397
}
7498

7599
String atType = resourceSpecificationCreateVO.getAtType();
76-
String entityType = ResourceTypeRegistry.getSpecEntityType(atType);
77-
78-
if (ResourceTypeRegistry.SPEC_TYPES.containsKey(atType)) {
100+
if (atType != null && ResourceTypeRegistry.SPEC_TYPES.containsKey(atType)) {
101+
String entityType = ResourceTypeRegistry.getSpecEntityType(atType);
79102
return createSubTypeSpec(resourceSpecificationCreateVO, entityType, atType);
80103
}
81104

resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/rest/ResourceApiController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ private void stampLastUpdate(Resource resource) {
7070
@Override
7171
public Mono<HttpResponse<ResourceVO>> createResource(@NonNull ResourceCreateVO resourceCreateVO) {
7272
String atType = resourceCreateVO.getAtType();
73-
String entityType = ResourceTypeRegistry.getResourceEntityType(atType);
74-
75-
if (ResourceTypeRegistry.RESOURCE_TYPES.containsKey(atType)) {
73+
if (atType != null && ResourceTypeRegistry.RESOURCE_TYPES.containsKey(atType)) {
74+
String entityType = ResourceTypeRegistry.getResourceEntityType(atType);
7675
return createSubTypeResource(resourceCreateVO, entityType, atType);
7776
}
7877

software-management/src/main/java/org/fiware/tmforum/softwaremanagement/rest/ResourceApiController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ private void stampLastUpdate(Resource resource) {
8383
@Override
8484
public Mono<HttpResponse<ResourceVO>> createResource(@NonNull ResourceCreateVO resourceCreateVO) {
8585
String atType = resourceCreateVO.getAtType();
86-
String entityType = ResourceTypeRegistry.getResourceEntityType(atType);
87-
88-
if (ResourceTypeRegistry.RESOURCE_TYPES.containsKey(atType)) {
86+
if (atType != null && ResourceTypeRegistry.RESOURCE_TYPES.containsKey(atType)) {
87+
String entityType = ResourceTypeRegistry.getResourceEntityType(atType);
8988
return createSubTypeResource(resourceCreateVO, entityType, atType);
9089
}
9190

software-management/src/main/java/org/fiware/tmforum/softwaremanagement/rest/ResourceSpecificationApiController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ public Mono<HttpResponse<ResourceSpecificationVO>> createResourceSpecification(
8585
}
8686

8787
String atType = resourceSpecificationCreateVO.getAtType();
88-
String entityType = ResourceTypeRegistry.getSpecEntityType(atType);
89-
90-
if (ResourceTypeRegistry.SPEC_TYPES.containsKey(atType)) {
88+
if (atType != null && ResourceTypeRegistry.SPEC_TYPES.containsKey(atType)) {
89+
String entityType = ResourceTypeRegistry.getSpecEntityType(atType);
9190
return createSubTypeSpec(resourceSpecificationCreateVO, entityType, atType);
9291
}
9392

0 commit comments

Comments
 (0)