Skip to content

Commit ea95cf9

Browse files
authored
Merge pull request #50 from yngwi/master
Version 0.4.2
2 parents fbfeff0 + 73567d0 commit ea95cf9

File tree

6 files changed

+72
-44
lines changed

6 files changed

+72
-44
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010
<groupId>eu.nampi</groupId>
1111
<artifactId>backend</artifactId>
12-
<version>0.4.1</version>
12+
<version>0.4.2</version>
1313
<name>nampi-backend</name>
1414
<description>The NAMPI backend</description>
1515

src/main/java/eu/nampi/backend/controller/EventController.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ public ResponseEntity<String> getEvents(
5656
@RequestParam("participantType") Optional<Resource> participantType,
5757
@RequestParam("participationType") Optional<Property> participationType,
5858
@RequestParam("place") Optional<Resource> place,
59-
@RequestParam("author") Optional<Resource> author) {
59+
@RequestParam("author") Optional<Resource> author,
60+
@RequestParam("source") Optional<Resource> source) {
6061
QueryParameters params = getParameters(page, pageIndex, limit, offset, orderBy, type, text);
6162
String result =
6263
eventRepository.findAll(params, lang, dates, aspect, aspectType, aspectUseType, participant,
63-
participantType, participationType, place, author);
64+
participantType, participationType, place, author, source);
6465
return new ResponseEntity<String>(result, HttpStatus.OK);
6566
}
6667

@@ -79,9 +80,12 @@ public ResponseEntity<String> postEvent(
7980
@Valid @RequestBody EventMutationPayload payload) {
8081
InsertResult result = eventRepository.insert(lang, payload.getTypes(), payload.getLabels(),
8182
asList(payload.getComments()), asList(payload.getTexts()), payload.getAuthors(),
82-
payload.getSource(), payload.getSourceLocation(), payload.getMainParticipant(),
83-
asList(payload.getOtherParticipants()), asList(payload.getAspects()),
84-
Optional.ofNullable(payload.getPlace()), Optional.ofNullable(payload.getDate()));
83+
payload.getSource(),
84+
Optional.ofNullable(payload.getSourceLocation())
85+
.map(location -> location.getString().isBlank() ? null : location),
86+
payload.getMainParticipant(), asList(payload.getOtherParticipants()),
87+
asList(payload.getAspects()), Optional.ofNullable(payload.getPlace()),
88+
Optional.ofNullable(payload.getDate()));
8589
HttpHeaders headers = new HttpHeaders();
8690
headers.add("Location", result.getEntity().getURI());
8791
return new ResponseEntity<String>(result.getResponseBody(), headers, HttpStatus.CREATED);
@@ -99,9 +103,12 @@ public ResponseEntity<String> putEvent(
99103
}
100104
String newEvent = eventRepository.update(lang, id, payload.getTypes(), payload.getLabels(),
101105
asList(payload.getComments()), asList(payload.getTexts()), payload.getAuthors(),
102-
payload.getSource(), payload.getSourceLocation(), payload.getMainParticipant(),
103-
asList(payload.getOtherParticipants()), asList(payload.getAspects()),
104-
Optional.ofNullable(payload.getPlace()), Optional.ofNullable(payload.getDate()));
106+
payload.getSource(),
107+
Optional.ofNullable(payload.getSourceLocation())
108+
.map(location -> location.getString().isBlank() ? null : location),
109+
payload.getMainParticipant(), asList(payload.getOtherParticipants()),
110+
asList(payload.getAspects()), Optional.ofNullable(payload.getPlace()),
111+
Optional.ofNullable(payload.getDate()));
105112
return new ResponseEntity<String>(newEvent, HttpStatus.CREATED);
106113
}
107114

src/main/java/eu/nampi/backend/model/EventMutationPayload.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class EventMutationPayload {
4646
@JsonDeserialize(using = ResourceDeserializer.class)
4747
private Resource source;
4848

49-
@NotNull
5049
@JsonDeserialize(using = LiteralDeserializer.class)
5150
private Literal sourceLocation;
5251

src/main/java/eu/nampi/backend/repository/ActRepository.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ public class ActRepository {
100100
Resource resLocation = row.getResource(VAR_LOC.toString());
101101
Literal litLocationText = row.getLiteral(VAR_LOC_TEXT.toString());
102102
model
103-
.add(main, Core.hasSourceLocation, resLocation)
104-
.add(resLocation, Core.hasText, litLocationText);
103+
.add(main, Core.hasSourceLocation, resLocation);
104+
Optional.of(row.getLiteral(VAR_LOC_TEXT.toString()))
105+
.ifPresent(text -> model.add(resLocation, Core.hasText, litLocationText));
105106
Optional
106107
.ofNullable(row.getResource(VAR_LOC_TYPE.toString()))
107108
.ifPresentOrElse(type -> model.add(resLocation, RDF.type, type),
@@ -172,28 +173,32 @@ public String findOne(Lang lang, UUID id) {
172173

173174
private void addData(WhereBuilder builder, boolean withTypes) {
174175
ExprFactory ef = builder.getExprFactory();
176+
WhereBuilder locationBuilder = new WhereBuilder()
177+
.addWhere(VAR_LOC, Core.hasText, VAR_LOC_TEXT);
178+
if (withTypes) {
179+
locationBuilder
180+
.addWhere(VAR_LOC, VAR_LOC_TEXT_TYPE, VAR_LOC_TEXT)
181+
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TEXT_TYPE), OWL.getURI())))
182+
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TEXT_TYPE), RDFS.getURI())))
183+
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TEXT_TYPE), RDF.getURI())));
184+
}
175185
builder
176186
.addWhere(VAR_MAIN, Core.isAuthoredBy, VAR_AUTHOR)
177187
.addWhere(VAR_AUTHOR, RDFS.label, VAR_AUTHOR_LABEL)
178188
.addWhere(VAR_MAIN, Core.hasInterpretation, VAR_INT)
179189
.addWhere(VAR_INT, RDFS.label, VAR_INT_LABEL)
180190
.addWhere(VAR_MAIN, Core.hasSourceLocation, VAR_LOC)
181-
.addWhere(VAR_LOC, Core.hasValue, VAR_LOC_TEXT)
182191
.addWhere(VAR_LOC, Core.hasSource, VAR_SRC)
183192
.addWhere(VAR_SRC, RDFS.label, VAR_SRC_LABEL)
184193
.addWhere(VAR_MAIN, Core.isAuthoredOn, VAR_DATE)
185-
.addWhere(VAR_DATE, Core.hasDateTime, VAR_DATE_TIME);
194+
.addWhere(VAR_DATE, Core.hasDateTime, VAR_DATE_TIME)
195+
.addOptional(locationBuilder);
186196
if (withTypes) {
187197
builder
188198
.addWhere(VAR_LOC, RDF.type, VAR_LOC_TYPE)
189199
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TYPE), OWL.getURI())))
190200
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TYPE), RDFS.getURI())))
191-
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TYPE), RDF.getURI())))
192-
.addWhere(VAR_LOC, VAR_LOC_TEXT_TYPE, VAR_LOC_TEXT)
193-
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TEXT_TYPE), OWL.getURI())))
194-
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TEXT_TYPE), RDFS.getURI())))
195-
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TEXT_TYPE), RDF.getURI())))
196-
.addFilter(ef.not(ef.sameTerm(VAR_LOC_TEXT_TYPE, Core.hasValue)));
201+
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOC_TYPE), RDF.getURI())));
197202
}
198203
}
199204

@@ -231,7 +236,7 @@ public void delete(UUID id) {
231236
}
232237

233238
public Resource insert(Lang lang, List<Resource> authors, Resource source,
234-
Literal sourceLocation) {
239+
Optional<Literal> sourceLocation) {
235240
HydraInsertBuilder builder =
236241
hydraBuilderFactory.insertBuilder(lang, ENDPOINT_NAME, Arrays.asList(Core.act),
237242
DEFAULT_LABEL, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
@@ -248,9 +253,10 @@ public Resource insert(Lang lang, List<Resource> authors, Resource source,
248253
Resource sourceLocationResource = ResourceFactory.createResource();
249254
builder
250255
.addInsert(builder.root, Core.hasSourceLocation, sourceLocationResource)
251-
.addInsert(sourceLocationResource, RDF.type, Core.sourceLocation)
252-
.addInsert(sourceLocationResource, Core.hasText, sourceLocation)
253-
.addInsert(sourceLocationResource, Core.hasSource, source);
256+
.addInsert(sourceLocationResource, Core.hasSource, source)
257+
.addInsert(sourceLocationResource, RDF.type, Core.sourceLocation);
258+
sourceLocation.ifPresent(location -> builder
259+
.addInsert(sourceLocationResource, Core.hasText, location));
254260
// Insert date
255261
Resource date = ResourceFactory.createResource();
256262
builder

src/main/java/eu/nampi/backend/repository/EventRepository.java

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ public class EventRepository {
144144
Resource date = row.getResource(VAR_ACT_DATE.toString());
145145
Resource location = row.getResource(VAR_LOCATION.toString());
146146
Resource source = row.getResource(VAR_SOURCE.toString());
147-
Literal locationText = row.getLiteral(VAR_LOCATION_TEXT.toString());
148147
model
149148
.add(main, Core.isInterpretationOf, act)
150149
.add(act, RDF.type, Core.act)
@@ -155,18 +154,21 @@ public class EventRepository {
155154
.add(date, RDF.type, Core.date)
156155
.add(date, Core.hasDateTime, row.getLiteral(VAR_ACT_DATE_TIME.toString()))
157156
.add(act, Core.hasSourceLocation, location)
158-
.add(location, Core.hasText, locationText)
159157
.add(location, Core.hasSource, source)
160158
.add(source, RDF.type, Core.source)
161159
.add(source, RDFS.label, row.getLiteral(VAR_SOURCE_LABEL.toString()));
162160
Optional
163161
.ofNullable(row.getResource(VAR_LOCATION_TYPE.toString()))
164162
.ifPresentOrElse(type -> model.add(location, RDF.type, type),
165163
() -> model.add(location, RDF.type, Core.sourceLocation));
166-
Optional
167-
.ofNullable(row.getResource(VAR_LOCATION_TEXT_TYPE.toString()))
168-
.map(type -> ResourceFactory.createProperty(type.getURI()))
169-
.ifPresent(type -> model.add(location, type, locationText));
164+
Optional.ofNullable(row.getLiteral(VAR_LOCATION_TEXT.toString()))
165+
.ifPresent(locationText -> {
166+
model.add(location, Core.hasText, locationText);
167+
Optional
168+
.ofNullable(row.getResource(VAR_LOCATION_TEXT_TYPE.toString()))
169+
.map(type -> ResourceFactory.createProperty(type.getURI()))
170+
.ifPresent(type -> model.add(location, type, locationText));
171+
});
170172
// Aspect
171173
Optional
172174
.ofNullable(row.getResource(VAR_ASPECT.toString()))
@@ -273,11 +275,12 @@ public class EventRepository {
273275
};
274276

275277
@Cacheable(
276-
key = "{#lang, #params.limit, #params.offset, #params.orderByClauses, #params.type, #params.text, #dates,#aspect, #aspectType, #aspectUseType, #participant, #participantType, #participationType, #place, #author}")
278+
key = "{#lang, #params.limit, #params.offset, #params.orderByClauses, #params.type, #params.text, #dates, #aspect, #aspectType, #aspectUseType, #participant, #participantType, #participationType, #place, #author, #source}")
277279
public String findAll(QueryParameters params, Lang lang, Optional<String> dates,
278280
Optional<Resource> aspect, Optional<Resource> aspectType, Optional<Property> aspectUseType,
279281
Optional<Resource> participant, Optional<Resource> participantType,
280-
Optional<Property> participationType, Optional<Resource> place, Optional<Resource> author) {
282+
Optional<Property> participationType, Optional<Resource> place, Optional<Resource> author,
283+
Optional<Resource> source) {
281284
HydraCollectionBuilder builder = hydraBuilderFactory.collectionBuilder(ENDPOINT_NAME,
282285
Core.event, Api.eventOrderByVar, params, false);
283286
ExprFactory ef = builder.ef;
@@ -347,6 +350,10 @@ public String findAll(QueryParameters params, Lang lang, Optional<String> dates,
347350
builder.mapper.add("author", Api.eventAuthorVar, author);
348351
author.ifPresent(resAuthor -> builder.coreData.addWhere(actWhere(false))
349352
.addFilter(ef.sameTerm(VAR_AUTHOR, resAuthor)));
353+
// Source data
354+
builder.mapper.add("source", Api.eventSourceVar, source);
355+
source.ifPresent(resSource -> builder.coreData.addWhere(actWhere(false))
356+
.addFilter(ef.sameTerm(VAR_SOURCE, resSource)));
350357
// Dates data
351358
if (hasDateSort || dates.isPresent()) {
352359
builder.coreData.addWhere(datesWhere(order, VAR_DATE_REAL_SORT, VAR_DATE));
@@ -397,27 +404,31 @@ public String findOne(Lang lang, UUID id) {
397404
private WhereBuilder actWhere(boolean withTypes) {
398405
WhereBuilder builder = new WhereBuilder();
399406
ExprFactory ef = builder.getExprFactory();
407+
WhereBuilder locationBuilder = new WhereBuilder()
408+
.addWhere(VAR_LOCATION, Core.hasText, VAR_LOCATION_TEXT);
409+
if (withTypes) {
410+
locationBuilder
411+
.addWhere(VAR_LOCATION, VAR_LOCATION_TEXT_TYPE, VAR_LOCATION_TEXT)
412+
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TEXT), OWL.getURI())))
413+
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TEXT), RDFS.getURI())))
414+
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TEXT), RDF.getURI())));
415+
}
400416
builder
401417
.addWhere(VAR_MAIN, Core.isInterpretationOf, VAR_ACT)
402418
.addWhere(VAR_ACT, Core.isAuthoredBy, VAR_AUTHOR)
403419
.addWhere(VAR_AUTHOR, RDFS.label, VAR_AUTHOR_LABEL)
404420
.addWhere(VAR_ACT, Core.isAuthoredOn, VAR_ACT_DATE)
405421
.addWhere(VAR_ACT_DATE, Core.hasDateTime, VAR_ACT_DATE_TIME)
406422
.addWhere(VAR_ACT, Core.hasSourceLocation, VAR_LOCATION)
407-
.addWhere(VAR_LOCATION, Core.hasText, VAR_LOCATION_TEXT)
408423
.addWhere(VAR_LOCATION, Core.hasSource, VAR_SOURCE)
409-
.addWhere(VAR_SOURCE, RDFS.label, VAR_SOURCE_LABEL);
424+
.addWhere(VAR_SOURCE, RDFS.label, VAR_SOURCE_LABEL)
425+
.addOptional(locationBuilder);
410426
if (withTypes) {
411427
builder
412428
.addWhere(VAR_LOCATION, RDF.type, VAR_LOCATION_TYPE)
413429
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TYPE), OWL.getURI())))
414430
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TYPE), RDFS.getURI())))
415-
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TYPE), RDF.getURI())))
416-
.addWhere(VAR_LOCATION, VAR_LOCATION_TEXT_TYPE, VAR_LOCATION_TEXT)
417-
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TEXT_TYPE), OWL.getURI())))
418-
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TEXT_TYPE), RDFS.getURI())))
419-
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TEXT_TYPE), RDF.getURI())))
420-
.addFilter(ef.not(ef.sameTerm(VAR_LOCATION_TEXT_TYPE, Core.hasValue)));
431+
.addFilter(ef.not(ef.strstarts(ef.str(VAR_LOCATION_TYPE), RDF.getURI())));
421432
}
422433
return builder;
423434
}
@@ -555,7 +566,7 @@ public void delete(UUID id) {
555566

556567
public InsertResult insert(Optional<UUID> optionalId, Lang lang, List<Resource> types,
557568
List<Literal> labels, List<Literal> comments, List<Literal> texts, List<Resource> authors,
558-
Resource source, Literal sourceLocation, ResourceCouple mainParticipant,
569+
Resource source, Optional<Literal> sourceLocation, ResourceCouple mainParticipant,
559570
List<ResourceCouple> otherParticipants, List<ResourceCouple> aspects,
560571
Optional<Resource> optionalPlace, Optional<DateRange> optionalDate) {
561572
validatePayload(lang, types, labels, comments, texts, authors, source, sourceLocation,
@@ -633,7 +644,7 @@ public InsertResult insert(Optional<UUID> optionalId, Lang lang, List<Resource>
633644

634645
public InsertResult insert(Lang lang, List<Resource> types, List<Literal> labels,
635646
List<Literal> comments, List<Literal> texts, List<Resource> authors, Resource source,
636-
Literal sourceLocation, ResourceCouple mainParticipant,
647+
Optional<Literal> sourceLocation, ResourceCouple mainParticipant,
637648
List<ResourceCouple> otherParticipants, List<ResourceCouple> aspects,
638649
Optional<Resource> optionalPlace, Optional<DateRange> optionalDate) {
639650
return insert(Optional.empty(), lang, types, labels, comments, texts, authors, source,
@@ -642,7 +653,7 @@ public InsertResult insert(Lang lang, List<Resource> types, List<Literal> labels
642653

643654
public String update(Lang lang, UUID id, List<Resource> types, List<Literal> labels,
644655
List<Literal> comments, List<Literal> texts, List<Resource> authors, Resource source,
645-
Literal sourceLocation, ResourceCouple mainParticipant,
656+
Optional<Literal> sourceLocation, ResourceCouple mainParticipant,
646657
List<ResourceCouple> otherParticipants, List<ResourceCouple> aspects,
647658
Optional<Resource> optionalPlace, Optional<DateRange> optionalDate) {
648659
validatePayload(lang, types, labels, comments, texts, authors, source, sourceLocation,
@@ -655,12 +666,16 @@ public String update(Lang lang, UUID id, List<Resource> types, List<Literal> lab
655666

656667
private void validatePayload(Lang lang, List<Resource> types,
657668
List<Literal> labels, List<Literal> comments, List<Literal> texts, List<Resource> authors,
658-
Resource source, Literal sourceLocation, ResourceCouple mainParticipant,
669+
Resource source, Optional<Literal> sourceLocation, ResourceCouple mainParticipant,
659670
List<ResourceCouple> otherParticipants, List<ResourceCouple> aspects,
660671
Optional<Resource> optionalPlace, Optional<DateRange> optionalDate) {
661672
HydraInsertBuilder builder = hydraBuilderFactory.insertBuilder(lang, ENDPOINT_NAME, types,
662673
labels, comments, texts, new ArrayList<>());
663674
builder.validateSubresources(Core.event, types);
675+
// Author
676+
authors.forEach(author -> builder.validateType(Core.author, author));
677+
// Source
678+
builder.validateType(Core.source, source);
664679
// Date
665680
optionalDate
666681
.ifPresent(date -> date.getStart().ifPresent(start -> date.getEnd().ifPresent(end -> {

src/main/java/eu/nampi/backend/vocabulary/Api.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ protected static Property property(String local) {
5454
public static Resource eventAspectUseTypeVar = resource("eventAspectUseTypeVariable");
5555
public static Resource eventAspectVar = resource("eventAspectVariable");
5656
public static Resource eventAuthorVar = resource("eventAuthorVariable");
57+
public static Resource eventSourceVar = resource("eventSourceVariable");
5758
public static Resource eventCollection = resource("eventCollection");
5859
public static Resource eventDatesVar = resource("eventDatesVariable");
5960
public static Resource eventOrderByVar = resource("eventOrderByVariable");

0 commit comments

Comments
 (0)