Skip to content

Commit

Permalink
Merge f7aa70d into 775e37b
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Wiedemann authored Oct 28, 2022
2 parents 775e37b + f7aa70d commit f5fe5d3
Show file tree
Hide file tree
Showing 103 changed files with 6,441 additions and 3,153 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/conformance-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
module: [party-catalog, resource-function-activation, resource-catalog, resource-inventory]
module: [party-catalog, resource-function-activation, resource-catalog, resource-inventory, service-catalog]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- unlabeled
env:
REGISTRY: quay.io
REPOSITORY: fiware
REPOSITORY: wi_stefan

jobs:

Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Build&Push image
run: |
mvn versions:set -DnewVersion=${{ needs.generate-version.outputs.version }}
mvn clean install deploy -DskipITs -DskipTests -Pdocker -Dimage.tag=${{ needs.generate-version.outputs.version }} -Dimage.registry="${{ env.REGISTRY }}" -Dimage.repository="${{ env.REPOSITORY }}"
mvn clean install deploy -DskipITs -DskipTests -Poci -Dimage.tag=${{ needs.generate-version.outputs.version }} -Dimage.registry="${{ env.REGISTRY }}" -Dimage.repository="${{ env.REPOSITORY }}"
git-release:
needs: ["generate-version","tmforum-apis"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

env:
REGISTRY: quay.io
REPOSITORY: fiware
REPOSITORY: wi_stefan

jobs:
generate-version:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ jobs:
id: test
run: |
mvn clean test integration-test
- name: Submitt report
id: coveralls
run: |
mvn jacoco:merge jacoco:report coveralls:report -Dcoveralls.token=${{ secrets.COVERALLS_TOKEN }} -Preport-coveralls
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.inject.Singleton;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
* Service to support validation of referential integrity.
Expand All @@ -32,6 +33,7 @@ public <T extends ReferencedEntity> Mono<Boolean> checkReferenceExists(List<T> r

return Mono.zip(
references.stream()
.filter(Objects::nonNull)
.map(ref -> referencesRepository.referenceExists(ref.getId().toString(), ref.getReferencedTypes())
.map(eVo -> true)
.defaultIfEmpty(false))
Expand Down
2,783 changes: 0 additions & 2,783 deletions log

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class AdditionalPropertyDeserializer extends AsArrayTypeDeserializer {
public AdditionalPropertyDeserializer(JavaType bt, TypeIdResolver idRes, String typePropertyName, boolean typeIdVisible, JavaType defaultImpl) {
super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
additionalPropertyObjectDeser = new AsPropertyTypeDeserializer(
TypeFactory.defaultInstance().constructType(new TypeReference<AdditionalPropertyObjectVO>() {
}),
TypeFactory.defaultInstance().constructType(new TypeReference<AdditionalPropertyObjectVO>() {}),
idRes,
NGSI_LD_TYPE_PROPERTY_NAME,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public EntityVOMapper(ObjectMapper objectMapper, EntitiesRepository entitiesRepo
this.entitiesRepository = entitiesRepository;
this.objectMapper
.addMixIn(AdditionalPropertyVO.class, AdditionalPropertyMixin.class);
this.objectMapper.findAndRegisterModules();
}

/**
Expand All @@ -66,7 +67,9 @@ public <T> Mono<T> fromEntityVO(EntityVO entityVO, Class<T> targetClass) {
if (!Arrays.stream(mappingEnabled.entityType()).toList().contains(entityVO.getType())) {
return Mono.error(new MappingException(String.format("Entity and Class type do not match - %s vs %s.", entityVO.getType(), Arrays.asList(mappingEnabled.entityType()))));
}
return getRelationshipMap(entityVO.getAdditionalProperties(), targetClass)
Map<String, AdditionalPropertyVO> additionalPropertyVOMap = Optional.ofNullable(entityVO.getAdditionalProperties()).orElse(Map.of());

return getRelationshipMap(additionalPropertyVOMap, targetClass)
.flatMap(relationshipMap -> fromEntityVO(entityVO, targetClass, relationshipMap));

}
Expand All @@ -80,7 +83,9 @@ public <T> Mono<T> fromEntityVO(EntityVO entityVO, Class<T> targetClass) {
* @return a single, emitting the map of related entities
*/
private <T> Mono<Map<String, EntityVO>> getRelationshipMap(Map<String, AdditionalPropertyVO> propertiesMap, Class<T> targetClass) {
return entitiesRepository.getEntities(getRelationshipObjects(propertiesMap, targetClass))
return Optional.ofNullable(entitiesRepository.getEntities(getRelationshipObjects(propertiesMap, targetClass)))
.orElse(Mono.just(List.of()))
.switchIfEmpty(Mono.just(List.of()))
.map(relationshipsList -> relationshipsList.stream().map(EntityVO.class::cast).collect(Collectors.toMap(e -> e.getId().toString(), e -> e)))
.defaultIfEmpty(Map.of());
}
Expand All @@ -106,7 +111,7 @@ private <T> Mono<T> fromEntityVO(EntityVO entityVO, Class<T> targetClass, Map<St
propertiesMap.put(EntityVO.JSON_PROPERTY_OPERATION_SPACE, entityVO.getOperationSpace());
propertiesMap.put(EntityVO.JSON_PROPERTY_CREATED_AT, propertyVOFromValue(entityVO.getCreatedAt()));
propertiesMap.put(EntityVO.JSON_PROPERTY_MODIFIED_AT, propertyVOFromValue(entityVO.getModifiedAt()));
propertiesMap.putAll(entityVO.getAdditionalProperties());
Optional.ofNullable(entityVO.getAdditionalProperties()).ifPresent(propertiesMap::putAll);

List<Mono<T>> singleInvocations = propertiesMap.entrySet().stream()
.map(entry -> getObjectInvocation(entry, constructedObject, relationShipMap, entityVO.getId().toString()))
Expand All @@ -129,7 +134,7 @@ private <T> Mono<T> fromEntityVO(EntityVO entityVO, Class<T> targetClass, Map<St
*/
private PropertyVO propertyVOFromValue(Object value) {
PropertyVO propertyVO = new PropertyVO();
propertyVO.setValue(propertyVO);
propertyVO.setValue(value);
return propertyVO;
}

Expand Down Expand Up @@ -297,10 +302,8 @@ private <T> Mono<T> invokeWithExceptionHandling(Method invocationMethod, T objec
try {
invocationMethod.invoke(objectUnderConstruction, invocationArgs);
return Mono.just(objectUnderConstruction);
} catch (IllegalAccessException | InvocationTargetException e) {
return Mono.error(e);
} catch (RuntimeException e) {
return Mono.error(e);
} catch (IllegalAccessException | InvocationTargetException | RuntimeException e) {
return Mono.error(new MappingException("Was not able to invoke method.", e));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -86,10 +87,11 @@ public <T> EntityVO toEntityVO(T entity) {
});

if (entityIdMethod.size() != 1) {
throw new IllegalArgumentException(String.format("The provided object declares %s id methods, exactly one is expected.", entityIdMethod.size()));
throw new MappingException(String.format("The provided object declares %s id methods, exactly one is expected.", entityIdMethod.size()));
}
if (entityTypeMethod.size() != 1) {
throw new IllegalArgumentException(String.format("The provided object declares %s type methods, exactly one is expected.", entityTypeMethod.size()));
throw new MappingException(String.format("The provided object declares %s type methods, exactly one is expected.", entityTypeMethod.size()));

}

return buildEntity(entity, entityIdMethod.get(0), entityTypeMethod.get(0), propertyMethods, propertyListMethods, geoPropertyMethods, relationshipMethods, relationshipListMethods);
Expand All @@ -112,17 +114,17 @@ private <T> EntityVO buildEntity(T entity, Method entityIdMethod, Method entityT
try {
Object entityIdObject = entityIdMethod.invoke(entity);
if (!(entityIdObject instanceof URI)) {
throw new IllegalArgumentException(String.format("The entityId method does not return a valid URI for entity %s.", entity));
throw new MappingException(String.format("The entityId method does not return a valid URI for entity %s.", entity));
}
entityVO.id((URI) entityIdObject);

Object entityTypeObject = entityTypeMethod.invoke(entity);
if (!(entityTypeObject instanceof String)) {
throw new IllegalArgumentException("The entityType method does not return a valid String.");
throw new MappingException("The entityType method does not return a valid String.");
}
entityVO.setType((String) entityTypeObject);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, "unknown-method", entity), e);
throw new MappingException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, "unknown-method", entity), e);
}

Map<String, AdditionalPropertyVO> additionalProperties = new LinkedHashMap<>();
Expand Down Expand Up @@ -275,14 +277,14 @@ private <T> Optional<Map.Entry<String, PropertyVO>> methodToPropertyEntry(T enti
if (propertyObject == null) {
return Optional.empty();
}
AttributeGetter attributeMapping = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new IllegalArgumentException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));
AttributeGetter attributeMapping = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new MappingException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));

PropertyVO propertyVO = new PropertyVO();
propertyVO.setValue(propertyObject);

return Optional.of(new AbstractMap.SimpleEntry<>(attributeMapping.targetName(), propertyVO));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, method, entity));
throw new MappingException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, method, entity));
}
}

Expand All @@ -295,12 +297,12 @@ private <T> Optional<Map.Entry<String, GeoPropertyVO>> methodToGeoPropertyEntry(
if (o == null) {
return Optional.empty();
}
AttributeGetter attributeMapping = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new IllegalArgumentException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));
AttributeGetter attributeMapping = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new MappingException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));
GeoPropertyVO geoPropertyVO = new GeoPropertyVO();
geoPropertyVO.setValue(o);
return Optional.of(new AbstractMap.SimpleEntry<>(attributeMapping.targetName(), geoPropertyVO));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, method, entity));
throw new MappingException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, method, entity));
}
}

Expand All @@ -314,7 +316,7 @@ private <T> Optional<Map.Entry<String, RelationshipVO>> methodToRelationshipEntr
return Optional.empty();
}
RelationshipVO relationshipVO = getRelationshipVO(method, relationShipObject);
AttributeGetter attributeMapping = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new IllegalArgumentException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));
AttributeGetter attributeMapping = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new MappingException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));
return Optional.of(new AbstractMap.SimpleEntry<>(attributeMapping.targetName(), relationshipVO));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new MappingException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, method, entity));
Expand All @@ -331,18 +333,20 @@ private <T> Optional<Map.Entry<String, RelationshipListVO>> methodToRelationship
return Optional.empty();
}
if (!(o instanceof List)) {
throw new IllegalArgumentException(String.format("Relationship list method %s::%s did not return a List.", entity, method));
throw new MappingException(String.format("Relationship list method %s::%s did not return a List.", entity, method));
}
List<Object> entityObjects = (List) o;

AttributeGetter attributeGetter = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new IllegalArgumentException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));
AttributeGetter attributeGetter = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new MappingException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));
RelationshipListVO relationshipVOS = new RelationshipListVO();

relationshipVOS.addAll(entityObjects.stream()
.filter(Objects::nonNull)
.map(entityObject -> getRelationshipVO(method, entityObject))
.toList());
return Optional.of(new AbstractMap.SimpleEntry<>(attributeGetter.targetName(), relationshipVOS));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, method, entity));
throw new MappingException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, method, entity));
}
}

Expand Down Expand Up @@ -408,9 +412,9 @@ private <T> Optional<Map.Entry<String, PropertyListVO>> methodToPropertyListEntr
return Optional.empty();
}
if (!(o instanceof List)) {
throw new IllegalArgumentException(String.format("Property list method %s::%s did not return a List.", entity, method));
throw new MappingException(String.format("Property list method %s::%s did not return a List.", entity, method));
}
AttributeGetter attributeMapping = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new IllegalArgumentException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));
AttributeGetter attributeMapping = getAttributeGetter(method.getAnnotations()).orElseThrow(() -> new MappingException(String.format(NO_MAPPING_DEFINED_FOR_METHOD_TEMPLATE, method)));
List<Object> entityObjects = (List) o;

PropertyListVO propertyVOS = new PropertyListVO();
Expand All @@ -425,7 +429,7 @@ private <T> Optional<Map.Entry<String, PropertyListVO>> methodToPropertyListEntr

return Optional.of(new AbstractMap.SimpleEntry<>(attributeMapping.targetName(), propertyVOS));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, method, entity));
throw new MappingException(String.format(WAS_NOT_ABLE_INVOKE_METHOD_TEMPLATE, method, entity));
}
}

Expand Down
Loading

0 comments on commit f5fe5d3

Please sign in to comment.