Skip to content

Commit

Permalink
fixes in the refactoring mainly caused by line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
vraybaud committed Jun 9, 2020
1 parent ac9c297 commit 85247f2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 33 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ If you want to build only one of the services, you can launch:
./gradlew entity-service:build
```

### Formatting the code

To format the code, we use Intellij built-in formatter with settings that can be found in the `config/settings` directory.

Import settings with `File/Manage IDE Settings/Import Settings...`.

You can use plugins like `Save Actions` (https://plugins.jetbrains.com/plugin/7642-save-actions) that applies changed code refactoring and optimized imports on a save.

### Working locally with Docker images

To work locally with a Docker image of a service without publishing it to Docker Hub, you can follow the below instructions:
Expand Down
Binary file added config/settings/stellio_format_settings.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -633,19 +633,16 @@ class EntityService(
private fun updatePropertiesOfAttribute(subject: Attribute, values: Map<String, List<Any>>) {
values.filterValues {
it[0] is Map<*, *>
}.mapValues {
expandValueAsMap(it.value)
}.filter {
!(NGSILD_PROPERTIES_CORE_MEMBERS.plus(NGSILD_RELATIONSHIPS_CORE_MEMBERS)).contains(it.key) &&
isAttributeOfType(it.value, NGSILD_PROPERTY_TYPE)
}.forEach { entry ->
if (!neo4jRepository.hasPropertyOfName(subject.id, entry.key))
throw BadRequestDataException("Property ${entry.key.extractShortTypeFromExpanded()} does not exist")
updatePropertyValues(subject.id, entry.key, entry.value)
}
.mapValues {
expandValueAsMap(it.value)
}
.filter {
!(NGSILD_PROPERTIES_CORE_MEMBERS.plus(NGSILD_RELATIONSHIPS_CORE_MEMBERS)).contains(it.key) &&
isAttributeOfType(it.value, NGSILD_PROPERTY_TYPE)
}
.forEach { entry ->
if (!neo4jRepository.hasPropertyOfName(subject.id, entry.key))
throw BadRequestDataException("Property ${entry.key.extractShortTypeFromExpanded()} does not exist")
updatePropertyValues(subject.id, entry.key, entry.value)
}
}

private fun updateRelationshipsOfAttribute(subject: Attribute, values: Map<String, List<Any>>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ class EntityHandlerTests {
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.exchange()
.expectStatus().isOk
.expectBody()
.json("{\"testedAt\":{\"type\":\"Property\",\"value\":{\"type\":\"DateTime\",\"@value\":\"2015-10-18T11:20:30.000001Z\"}},\"@context\":\"$NGSILD_CORE_CONTEXT\"}")
.expectBody().json(
"{\"testedAt\":{\"type\":\"Property\",\"value\":{\"type\":\"DateTime\",\"@value\":\"2015-10-18T11:20:30.000001Z\"}},\"@context\":\"$NGSILD_CORE_CONTEXT\"}"
)
}

@Test
Expand All @@ -284,8 +285,9 @@ class EntityHandlerTests {
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.exchange()
.expectStatus().isOk
.expectBody()
.json("{\"testedAt\":{\"type\":\"Property\",\"value\":{\"type\":\"Date\",\"@value\":\"2015-10-18\"}},\"@context\":\"$NGSILD_CORE_CONTEXT\"}")
.expectBody().json(
"{\"testedAt\":{\"type\":\"Property\",\"value\":{\"type\":\"Date\",\"@value\":\"2015-10-18\"}},\"@context\":\"$NGSILD_CORE_CONTEXT\"}"
)
}

@Test
Expand All @@ -312,8 +314,9 @@ class EntityHandlerTests {
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.exchange()
.expectStatus().isOk
.expectBody()
.json("{\"testedAt\":{\"type\":\"Property\",\"value\":{\"type\":\"Time\",\"@value\":\"11:20:30\"}},\"@context\":\"$NGSILD_CORE_CONTEXT\"}")
.expectBody().json(
"{\"testedAt\":{\"type\":\"Property\",\"value\":{\"type\":\"Time\",\"@value\":\"11:20:30\"}},\"@context\":\"$NGSILD_CORE_CONTEXT\"}"
)
}

@Test
Expand Down Expand Up @@ -391,8 +394,9 @@ class EntityHandlerTests {
.bodyValue(jsonLdFile)
.exchange()
.expectStatus().isEqualTo(HttpStatus.MULTI_STATUS)
.expectBody()
.json("{\"updated\":[\"fishNumber\"],\"notUpdated\":[{\"attributeName\":\"wrongAttribute\",\"reason\":\"overwrite disallowed\"}]}")
.expectBody().json(
"{\"updated\":[\"fishNumber\"],\"notUpdated\":[{\"attributeName\":\"wrongAttribute\",\"reason\":\"overwrite disallowed\"}]}"
)

verify { entityService.exists(eq("urn:ngsi-ld:BreedingService:0214")) }
verify { entityService.appendEntityAttributes(eq("urn:ngsi-ld:BreedingService:0214"), any(), eq(false)) }
Expand Down Expand Up @@ -613,7 +617,7 @@ class EntityHandlerTests {
.header("Link", "<$aquacContext>; rel=http://www.w3.org/ns/json-ld#context; type=application/ld+json")
.bodyValue(jsonLdFile)
.exchange()
.expectStatus().isEqualTo(HttpStatus.MULTI_STATUS)
.expectStatus().isEqualTo(HttpStatus.NO_CONTENT)

verify { entityService.exists(eq("urn:ngsi-ld:DeadFishes:019BN")) }
verify { entityService.updateEntityAttributes(eq(entityId), any(), eq(aquacContext!!)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class TemporalEntityHandler(
@RequestHeader httpHeaders: HttpHeaders,
@PathVariable entityId: String,
@RequestBody body: Mono<String>
):
Mono<ResponseEntity<*>> {
): Mono<ResponseEntity<*>> {
val contextLink = extractContextFromLinkHeader(httpHeaders.getOrEmpty("Link"))

return body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ class AttributeInstanceServiceTests : TimescaleBasedTests() {
(1..10).forEach { _ -> attributeInstanceService.create(gimmeAttributeInstance()).block() }

val temporalQuery = TemporalQuery(
emptyList(), TemporalQuery.Timerel.AFTER, Instant.now().atZone(ZoneOffset.UTC).minusHours(1),
null, null, null
emptyList(),
TemporalQuery.Timerel.AFTER,
Instant.now().atZone(ZoneOffset.UTC).minusHours(1),
null,
null,
null
)
val enrichedEntity = attributeInstanceService.search(temporalQuery, temporalEntityAttribute)

Expand Down Expand Up @@ -155,8 +159,12 @@ class AttributeInstanceServiceTests : TimescaleBasedTests() {
}

val temporalQuery = TemporalQuery(
emptyList(), TemporalQuery.Timerel.AFTER, Instant.now().atZone(ZoneOffset.UTC).minusHours(1),
null, null, null
emptyList(),
TemporalQuery.Timerel.AFTER,
Instant.now().atZone(ZoneOffset.UTC).minusHours(1),
null,
null,
null
)
val enrichedEntity = attributeInstanceService.search(temporalQuery, temporalEntityAttribute)

Expand All @@ -174,8 +182,12 @@ class AttributeInstanceServiceTests : TimescaleBasedTests() {
(1..10).forEach { _ -> attributeInstanceService.create(gimmeAttributeInstance()).block() }

val temporalQuery = TemporalQuery(
emptyList(), TemporalQuery.Timerel.AFTER, Instant.now().atZone(ZoneOffset.UTC).minusHours(1),
null, null, null
emptyList(),
TemporalQuery.Timerel.AFTER,
Instant.now().atZone(ZoneOffset.UTC).minusHours(1),
null,
null,
null
)
val enrichedEntity =
attributeInstanceService.search(temporalQuery, temporalEntityAttribute.copy(id = UUID.randomUUID()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ object NgsiLdParsingUtils {
}

fun extractShortTypeFromPayload(payload: Map<String, Any>): String =
// TODO is it always after a '/' ? can't it be after a '#' ? (https://redmine.eglobalmark.com/issues/852)
// TODO do a clean implementation using info from @context
/*
* TODO do a clean implementation using info from @context
* TODO is it always after a '/' ? can't it be after a '#' ? (https://redmine.eglobalmark.com/issues/852)
*/
(payload["@type"] as List<String>)[0].substringAfterLast("/").substringAfterLast("#")

/**
Expand Down Expand Up @@ -407,8 +409,10 @@ object NgsiLdParsingUtils {
}

fun String.extractShortTypeFromExpanded(): String =
// TODO is it always after a '/' ? can't it be after a '#' ? (https://redmine.eglobalmark.com/issues/852)
// TODO do a clean implementation using info from @context
/*
* TODO is it always after a '/' ? can't it be after a '#' ? (https://redmine.eglobalmark.com/issues/852)
* TODO do a clean implementation using info from @context
*/
this.substringAfterLast("/").substringAfterLast("#")

fun String.toRelationshipTypeName(): String =
Expand Down

0 comments on commit 85247f2

Please sign in to comment.