@@ -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 -> {
0 commit comments