Skip to content

Commit

Permalink
[Metadata] Add metadata on all opensilex model
Browse files Browse the repository at this point in the history
  • Loading branch information
IKIOU Hamza authored and Crejak committed Sep 8, 2023
1 parent 2b2d811 commit bf72119
Show file tree
Hide file tree
Showing 134 changed files with 1,629 additions and 440 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Response createAnnotation(@Valid AnnotationCreationDTO dto) throws Except
try {
AnnotationDAO dao = new AnnotationDAO(sparql);
AnnotationModel model = dto.newModel();
model.setCreator(currentUser.getUri());
model.setPublisher(currentUser.getUri());

model = dao.create(model);
return new CreatedUriResponse(model.getUri()).getResponse();
Expand Down Expand Up @@ -201,7 +201,7 @@ public Response searchAnnotations(
@ApiParam(value = "Description (regex)", example = "The pest attack") @QueryParam("description") String descriptionPattern,
@ApiParam(value = "Target URI", example = "http://www.opensilex.org/demo/2018/o18000076") @QueryParam("target") URI target,
@ApiParam(value = "Motivation URI", example = "http://www.w3.org/ns/oa#describing") @QueryParam("motivation") URI motivation,
@ApiParam(value = "Author URI", example = "http://opensilex.dev/users#Admin.OpenSilex") @QueryParam("author") URI creator,
@ApiParam(value = "Author URI", example = "http://opensilex.dev/users#Admin.OpenSilex") @QueryParam("author") URI publisher,
@ApiParam(value = "List of fields to sort as an array of fieldName=asc|desc", example = "author=asc") @DefaultValue("created=desc") @QueryParam("order_by") List<OrderBy> orderByList,
@ApiParam(value = "Page number", example = "0") @QueryParam("page") @DefaultValue("0") @Min(0) int page,
@ApiParam(value = "Page size", example = "20") @QueryParam("page_size") @DefaultValue("20") @Min(0) int pageSize
Expand All @@ -213,7 +213,7 @@ public Response searchAnnotations(
descriptionPattern,
target,
motivation,
creator,
publisher,
currentUser.getLanguage(),
orderByList,
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public AnnotationModel newModel() {

model.setUri(uri);
model.setDescription(description);
model.setCreated(OffsetDateTime.now());
model.setTargets(targets);

MotivationModel motivationModel = new MotivationModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
import org.opensilex.core.annotation.dal.MotivationModel;

import java.net.URI;
import java.time.OffsetDateTime;
import java.util.List;

/**
* @author Renaud COLIN
*/
@ApiModel
@JsonPropertyOrder({
"uri", "description", "targets", "motivation", "created", "author",
"uri", "description", "targets", "motivation", "published", "publisher",
})
public class AnnotationGetDTO {

Expand All @@ -38,12 +39,11 @@ public class AnnotationGetDTO {
@JsonProperty("motivation")
protected MotivationGetDTO motivation;

@JsonProperty("published")
protected OffsetDateTime published;

@JsonProperty("created")
protected String created;

@JsonProperty("author")
protected URI author;
@JsonProperty("publisher")
protected URI publisher;

public AnnotationGetDTO() {
}
Expand All @@ -53,8 +53,8 @@ public AnnotationGetDTO(AnnotationModel model) {

description = model.getDescription();
targets = model.getTargets();
created = model.getCreated().toString();
author = model.getCreator();
published = model.getPublicationDate();
publisher = model.getPublisher();

MotivationModel motivationModel = model.getMotivation();
motivation = new MotivationGetDTO(motivationModel);
Expand Down Expand Up @@ -86,25 +86,15 @@ public void setTargets(List<URI> targets) {
this.targets = targets;
}

@ApiModelProperty(value = "Creation date" ,example = "2019-09-08T12:00:00+01:00")
public String getCreated() {
return created;
}

public void setCreated(String created) {
this.created = created;
@ApiModelProperty(value = "Annotation publisher URI" ,example = "http://opensilex.dev/users#Admin.OpenSilex")
public URI getPublisher() {
return publisher;
}

@ApiModelProperty(value = "Annotation author URI" ,example = "http://opensilex.dev/users#Admin.OpenSilex")
public URI getAuthor() {
return author;
public void setPublisher(URI publisher) {
this.publisher = publisher;
}

public void setAuthor(URI author) {
this.author = author;
}


public MotivationGetDTO getMotivation() {
return motivation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ private void appendTargetFilter(ElementGroup annotationGraphGroupElem, URI targe
}
}

private void appendCreatorFilter(ElementGroup annotationGraphGroupElem, URI creator) throws Exception {
private void appendPublisherFilter(ElementGroup annotationGraphGroupElem, URI publisher) throws Exception {

if (creator != null) {
Expr targetEqFilter = SPARQLQueryHelper.eq(AnnotationModel.CREATOR_FIELD, creator);
if (publisher != null) {
Expr targetEqFilter = SPARQLQueryHelper.eq(AnnotationModel.PUBLISHER_FIELD, publisher);
annotationGraphGroupElem.addElementFilter(new ElementFilter(targetEqFilter));
}

Expand All @@ -125,7 +125,7 @@ private void appendCreatorFilter(ElementGroup annotationGraphGroupElem, URI crea
public ListWithPagination<AnnotationModel> search(String bodyValuePattern,
URI target,
URI motivation,
URI creator,
URI publisher,
String lang,
List<OrderBy> orderByList,
Integer page,
Expand Down Expand Up @@ -162,7 +162,7 @@ public ListWithPagination<AnnotationModel> search(String bodyValuePattern,
appendTargetFilter(annotationGraphGroupElem, target);
appendBodyValueFilter(annotationGraphGroupElem, bodyValuePattern);
appendMotivationFilter(annotationGraphGroupElem, motivation);
appendCreatorFilter(annotationGraphGroupElem, creator);
appendPublisherFilter(annotationGraphGroupElem, publisher);

// add specific ORDER BY directly to the select builder
specificOrderMap.forEach(selectBuilder::addOrderBy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ public class AnnotationModel extends SPARQLResourceModel implements ClassURIGene

public static final String GRAPH = "annotation";

@SPARQLProperty(
ontology = DCTerms.class,
property = "created",
required = true
)
private OffsetDateTime created;

@SPARQLProperty(
ontology = OA.class,
property = "bodyValue",
Expand All @@ -63,14 +56,6 @@ public class AnnotationModel extends SPARQLResourceModel implements ClassURIGene
private List<URI> targets;
public static final String TARGET_FIELD = "targets";

public OffsetDateTime getCreated() {
return created;
}

public void setCreated(OffsetDateTime created) {
this.created = created;
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import org.opensilex.core.ontology.Oeev;
import org.opensilex.core.ontology.Oeso;
import org.opensilex.nosql.mongodb.MongoDBService;
import org.opensilex.security.account.dal.AccountDAO;
import org.opensilex.security.account.dal.AccountModel;
import org.opensilex.security.authentication.ApiCredential;
import org.opensilex.security.authentication.ApiCredentialGroup;
import org.opensilex.security.authentication.ApiProtected;
import org.opensilex.security.authentication.injection.CurrentUser;
import org.opensilex.security.user.api.UserGetDTO;
import org.opensilex.server.response.*;
import org.opensilex.server.rest.validation.ValidURI;
import org.opensilex.server.rest.validation.date.ValidOffsetDateTime;
Expand All @@ -48,6 +50,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static org.opensilex.core.geospatial.dal.GeospatialDAO.geoJsonToGeometry;

Expand Down Expand Up @@ -135,7 +138,9 @@ public Response createArea(
else{
//Create an event with the rdfType from event
areaDTO.event.setTargets(Arrays.asList(areaURI));
eventDAO.create(areaDTO.event.toModel());
EventModel eventModel = areaDTO.event.toModel();
eventModel.setPublisher(currentUser.getUri());
eventDAO.create(eventModel);
}
}
else{
Expand Down Expand Up @@ -207,9 +212,20 @@ public Response getByURI(
switch (eventList.getList().size()) {
case 1:
EventModel eventByURI = eventDAO.get(eventList.getList().get(0).getUri(), currentUser);
return new SingleObjectResponse<>(AreaGetDTO.fromModel(model, geometryByURI, eventByURI)).getResponse();
AreaGetDTO dto = AreaGetDTO.fromModel(model, geometryByURI, eventByURI);
if (Objects.nonNull(model.getPublisher())) {
dto.setPublisher(UserGetDTO.fromModel(new AccountDAO(sparql).get(model.getPublisher())));
}
if (Objects.nonNull(eventByURI.getPublisher())) {
dto.getEvent().setPublisher(UserGetDTO.fromModel(new AccountDAO(sparql).get(eventByURI.getPublisher())));
}
return new SingleObjectResponse<>(dto).getResponse();
case 0:
return new SingleObjectResponse<>(AreaGetDTO.fromModel(model, geometryByURI)).getResponse();
dto = AreaGetDTO.fromModel(model, geometryByURI);
if (Objects.nonNull(model.getPublisher())) {
dto.setPublisher(UserGetDTO.fromModel(new AccountDAO(sparql).get(model.getPublisher())));
}
return new SingleObjectResponse<>(dto).getResponse();
default:
return new ErrorResponse(
Response.Status.UNAUTHORIZED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
import org.opensilex.core.event.api.EventGetDTO;
import org.opensilex.core.event.dal.EventModel;
import org.opensilex.core.geospatial.dal.GeospatialModel;
import org.opensilex.security.user.api.UserGetDTO;
import org.opensilex.sparql.deserializer.SPARQLDeserializers;

import java.net.URI;
import java.net.URISyntaxException;
import java.time.OffsetDateTime;
import java.util.Objects;

import static org.opensilex.core.geospatial.dal.GeospatialDAO.geometryToGeoJson;

Expand All @@ -30,7 +33,7 @@
*
* @author Jean Philippe VERT
*/
@JsonPropertyOrder({"uri", "rdf_type", "is_structural_area","name", "description", "author", "geometry","event"})
@JsonPropertyOrder({"uri", "rdf_type", "is_structural_area","name", "description", "publisher", "geometry", "event", "publication_date", "last_updated_date"})
public class AreaGetDTO {
/**
* Area URI
Expand Down Expand Up @@ -64,15 +67,21 @@ public class AreaGetDTO {
protected String description;

/**
* author
* publisher
*/
protected URI author;
protected UserGetDTO publisher;

/**
* event of the Area
*/
protected EventGetDTO event;

@JsonProperty("publication_date")
protected OffsetDateTime publicationDate;

@JsonProperty("last_updated_date")
protected OffsetDateTime lastUpdatedDate;

/**
* Convert Area Model into Area DTO
*
Expand Down Expand Up @@ -122,11 +131,17 @@ private static AreaGetDTO dtoWithoutGeometry(AreaModel model) {
dto.setUri(model.getUri());
dto.setName(model.getName());
dto.setRdfType(model.getType());
dto.setAuthor(model.getCreator());

if (model.getDescription() != null) {
dto.setDescription(model.getDescription());
}
if (Objects.nonNull(model.getPublicationDate())) {
dto.setPublicationDate(model.getPublicationDate());
}
if (Objects.nonNull(model.getLastUpdateDate())) {
dto.setLastUpdatedDate(model.getLastUpdateDate());
}

return dto;
}

Expand Down Expand Up @@ -199,12 +214,12 @@ public void setDescription(String description) {
this.description = description;
}

public URI getAuthor() {
return author;
public UserGetDTO getPublisher() {
return publisher;
}

public void setAuthor(URI author) {
this.author = author;
public void setPublisher(UserGetDTO publisher) {
this.publisher = publisher;
}

public EventGetDTO getEvent() {
Expand All @@ -214,4 +229,20 @@ public EventGetDTO getEvent() {
public void setEvent(EventGetDTO event) {
this.event = event;
}

public OffsetDateTime getPublicationDate() {
return publicationDate;
}

public void setPublicationDate(OffsetDateTime publicationDate) {
this.publicationDate = publicationDate;
}

public OffsetDateTime getLastUpdatedDate() {
return lastUpdatedDate;
}

public void setLastUpdatedDate(OffsetDateTime lastUpdatedDate) {
this.lastUpdatedDate = lastUpdatedDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public AreaModel(URI uri, String name, URI type, String description, URI author)
this.setName(name);
this.setType(type);
this.setDescription(description);
setCreator(author);
setPublisher(author);

if (uri != null) {
uri = new URI(SPARQLDeserializers.getExpandedURI(uri.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public Response addListData(

for (DataCreationDTO dto : dtoList) {
DataModel model = dto.newModel();
model.setPublisher(user.getUri());
dataList.add(model);
}

Expand Down Expand Up @@ -1243,6 +1244,7 @@ public Response importCSVData(
//Transactions so that we don't create any Data or Annotations if either fail
nosql.startTransaction();
sparql.startTransaction();
data.forEach(dataModel -> dataModel.setPublisher(user.getUri()));
dao.createAll(data);

if(!validation.getVariablesToDevices().isEmpty()){
Expand Down Expand Up @@ -1557,7 +1559,7 @@ private boolean validateCSVRow(
boolean validRow = true;

ParsedDateTimeMongo parsedDateTimeMongo = null;

List<URI> experiments = new ArrayList<>();
SPARQLNamedResourceModel target = null;

Expand Down Expand Up @@ -1755,7 +1757,7 @@ else if (headerByIndex.get(colIndex).equalsIgnoreCase(annotationHeader)){
if(!StringUtils.isEmpty(annotation)){
annotationFromAnnotationColumn = new AnnotationModel();
annotationFromAnnotationColumn.setDescription(annotation.trim());
annotationFromAnnotationColumn.setCreator(user.getUri());
annotationFromAnnotationColumn.setPublisher(user.getUri());
MotivationModel motivationModel = new MotivationModel();
motivationModel.setUri(URI.create(OA.commenting.getURI()));
annotationFromAnnotationColumn.setMotivation(motivationModel);
Expand Down Expand Up @@ -1931,13 +1933,6 @@ else if (headerByIndex.get(colIndex).equalsIgnoreCase(annotationHeader)){
}else{
if(validRow){
annotationFromAnnotationColumn.setTargets(Collections.singletonList( target==null ? object.getUri() : target.getUri()));
Instant usedInstant = parsedDateTimeMongo.getInstant();
if(!parsedDateTimeMongo.getIsDateTime()){
String onlyDateString = parsedDateTimeMongo.getInstant().toString().substring(0, 11);
String setToMidday = onlyDateString + "12:00:00Z";
usedInstant = Instant.parse( setToMidday );
}
annotationFromAnnotationColumn.setCreated(usedInstant.atOffset(ZoneOffset.ofTotalSeconds(0)));
csvValidation.addToAnnotationsOnObjects(annotationFromAnnotationColumn);
}
}
Expand Down
Loading

0 comments on commit bf72119

Please sign in to comment.