Skip to content

Commit

Permalink
431555 Se elimina campo defaultVocabulary
Browse files Browse the repository at this point in the history
  • Loading branch information
sasierrassis committed May 22, 2024
1 parent 762031e commit 8bb6b93
Show file tree
Hide file tree
Showing 16 changed files with 15 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import org.upm.inesdata.vocabulary.transformer.JsonObjectToVocabularyTransformer;
import org.upm.inesdata.vocabulary.validator.VocabularyValidator;

import java.util.Map;

import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.EDC_VOCABULARY_TYPE;

import java.util.Map;

/**
* Extension that provides an API for managing vocabularies
*/
Expand Down Expand Up @@ -74,14 +74,6 @@ public VocabularyService vocabularyService() {
return new VocabularyServiceImpl(vocabularyIndex, transactionContext);
}

/**
* Provides a default in memory vocabularyIndex
*/
@Provider(isDefault = true)
public VocabularyIndex defaultVocabularyIndex() {
return getVocabularyIndex();
}

/**
* Initializes the service
*/
Expand All @@ -107,14 +99,4 @@ public void initialize(ServiceExtensionContext context) {
healthCheckService.addLivenessProvider(() -> successResult);
}
}

/**
* Creates a InMemoryVocabularyIndex if not exists
*/
private InMemoryVocabularyIndex getVocabularyIndex() {
if (defaultVocabularyIndex == null) {
defaultVocabularyIndex = new InMemoryVocabularyIndex();
}
return defaultVocabularyIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jakarta.json.JsonObject;
import org.eclipse.edc.api.model.ApiCoreSchema;
import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractOffer;
import org.upm.inesdata.spi.vocabulary.domain.Vocabulary;

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
Expand Down Expand Up @@ -126,8 +127,7 @@ record VocabularyOutputSchema(
"@id": "vocabularyId",
"name": "vocabulary name",
"jsonSchema": "{ \\"title\\": \\"vocabulary\\", \\"type\\": \\"object\\", \\"properties\\": { \\"name\\": { \\"type\\": \\"string\\", \\"title\\": \\"Name\\" }, \\"dct:keyword\\": { \\"type\\": \\"array\\", \\"title\\": \\"Keywords\\", \\"items\\": { \\"type\\": \\"string\\" } } }, \\"required\\": [ \\"name\\" ], \\"@context\\": { \\"dct\\": \\"http:\\/\\/purl.org\\/dc\\/terms\\/\" } }",
"category": "dataset",
"defaultVocabulary": true
"category": "dataset"
}
""";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.eclipse.edc.api.model.IdResponse;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;
Expand All @@ -28,8 +28,6 @@
import static org.eclipse.edc.web.spi.exception.ServiceResultHandler.exceptionMapper;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.EDC_VOCABULARY_TYPE;

import org.eclipse.edc.api.model.IdResponse;

/**
* Implementation of the controller for {@link Vocabulary} managing.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.eclipse.edc.spi.result.ServiceResult;
import org.eclipse.edc.transaction.spi.TransactionContext;

import org.upm.inesdata.spi.vocabulary.VocabularyIndex;
import org.upm.inesdata.spi.vocabulary.VocabularyService;
import org.upm.inesdata.spi.vocabulary.domain.Vocabulary;
Expand Down Expand Up @@ -43,19 +42,10 @@ public ServiceResult<List<Vocabulary>> search() {
@Override
public ServiceResult<Vocabulary> create(Vocabulary vocabulary) {
return transactionContext.execute(() -> {
// Managing default vocabulary
var defaultVocabulary = index.getDefaultVocabulary();

// Create new vocabulary
var createResult = index.create(vocabulary);

if (createResult.succeeded()) {
// There is only a default vocabulary
if (defaultVocabulary != null && vocabulary.isDefaultVocabulary()) {
defaultVocabulary.setDefaultVocabulary(false);
index.updateVocabulary(defaultVocabulary);
}

return ServiceResult.success(vocabulary);
}
return ServiceResult.fromFailure(createResult);
Expand All @@ -73,19 +63,8 @@ public ServiceResult<Vocabulary> delete(String vocabularyId) {
@Override
public ServiceResult<Vocabulary> update(Vocabulary vocabulary) {
return transactionContext.execute(() -> {
// Managing default vocabulary
var defaultVocabulary = index.getDefaultVocabulary();

// Update vocabulary
var updatedVocabulary = index.updateVocabulary(vocabulary);

// There is only a default vocabulary
if (defaultVocabulary != null && vocabulary.isDefaultVocabulary() &&
! defaultVocabulary.getId().equals(vocabulary.getId())) {
defaultVocabulary.setDefaultVocabulary(false);
index.updateVocabulary(defaultVocabulary);
}

return ServiceResult.from(updatedVocabulary);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.upm.inesdata.vocabulary.storage;

import org.eclipse.edc.spi.result.StoreResult;
import org.upm.inesdata.spi.vocabulary.domain.Vocabulary;
import org.upm.inesdata.spi.vocabulary.VocabularyIndex;
import org.upm.inesdata.spi.vocabulary.domain.Vocabulary;

import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -103,18 +103,4 @@ public StoreResult<Vocabulary> updateVocabulary(Vocabulary vocabulary) {
private Vocabulary delete(String vocabularyId) {
return cache.remove(vocabularyId);
}

@Override
public Vocabulary getDefaultVocabulary() {
lock.readLock().lock();
try {
return cache.values().stream()
.filter(vocabulary -> vocabulary.isDefaultVocabulary())
.findFirst()
.orElse(null);
} finally {
lock.readLock().unlock();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.JsonBuilderFactory;
import jakarta.json.JsonObject;

import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.jetbrains.annotations.NotNull;
Expand All @@ -12,12 +11,10 @@

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;

import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.EDC_VOCABULARY_TYPE;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_CATEGORY;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_JSON_SCHEMA;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_NAME;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_CATEGORY;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_DEFAULT_VOCABULARY;


/**
Expand All @@ -43,8 +40,7 @@ public JsonObjectFromVocabularyTransformer(JsonBuilderFactory jsonFactory, Objec
.add(TYPE, EDC_VOCABULARY_TYPE)
.add(PROPERTY_NAME, vocabulary.getName())
.add(PROPERTY_JSON_SCHEMA, vocabulary.getJsonSchema())
.add(PROPERTY_CATEGORY, vocabulary.getCategory())
.add(PROPERTY_DEFAULT_VOCABULARY, vocabulary.isDefaultVocabulary());
.add(PROPERTY_CATEGORY, vocabulary.getCategory());

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import org.jetbrains.annotations.Nullable;
import org.upm.inesdata.spi.vocabulary.domain.Vocabulary;

import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_CATEGORY;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_JSON_SCHEMA;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_NAME;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_CATEGORY;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_DEFAULT_VOCABULARY;

/**
* Converts from an {@link Vocabulary} as a {@link JsonObject} in JSON-LD expanded form to an {@link Vocabulary}.
Expand All @@ -33,14 +32,9 @@ public JsonObjectToVocabularyTransformer() {
case PROPERTY_NAME -> value -> builder.name(transformString(value, context));
case PROPERTY_JSON_SCHEMA -> value -> builder.jsonSchema(transformString(value, context));
case PROPERTY_CATEGORY -> value -> builder.category(transformString(value, context));
case PROPERTY_DEFAULT_VOCABULARY -> value -> builder.defaultVocabulary(transformBoolean(value, context));
default -> doNothing();
});

if (!jsonObject.containsKey(PROPERTY_DEFAULT_VOCABULARY)) {
builder.defaultVocabulary(false);
}

return builderResult(builder::build, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;
import jakarta.json.stream.JsonParsingException;
import java.io.StringReader;
import org.eclipse.edc.validator.jsonobject.JsonLdPath;
import org.eclipse.edc.validator.spi.ValidationResult;
import org.eclipse.edc.validator.spi.Validator;

import java.io.StringReader;
import java.util.Optional;

import static java.lang.String.format;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.eclipse.edc.validator.jsonobject.validators.OptionalIdNotBlank;
import org.eclipse.edc.validator.spi.Validator;

import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_CATEGORY;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_JSON_SCHEMA;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_NAME;
import static org.upm.inesdata.spi.vocabulary.domain.Vocabulary.PROPERTY_CATEGORY;

/**
* Validator for Vocabulary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
import org.eclipse.edc.transaction.spi.TransactionContext;
import org.jetbrains.annotations.Nullable;

import org.upm.inesdata.spi.vocabulary.VocabularyIndex;
import org.upm.inesdata.spi.vocabulary.domain.Vocabulary;
import org.upm.inesdata.vocabulary.sql.index.schema.VocabularyStatements;
import org.upm.inesdata.spi.vocabulary.VocabularyIndex;

import java.sql.Connection;
import java.sql.ResultSet;
Expand Down Expand Up @@ -83,7 +82,6 @@ public StoreResult<Void> create(Vocabulary vocabulary) {
vocabulary.getCreatedAt(),
vocabulary.getName(),
vocabulary.getCategory(),
vocabulary.isDefaultVocabulary(),
toJson(vocabulary.getJsonSchema())
);

Expand Down Expand Up @@ -124,7 +122,6 @@ public StoreResult<Vocabulary> updateVocabulary(Vocabulary vocabulary) {
vocabulary.getName(),
toJson(vocabulary.getJsonSchema()),
vocabulary.getCategory(),
vocabulary.isDefaultVocabulary(),
vocabularyId
);

Expand All @@ -138,18 +135,6 @@ public StoreResult<Vocabulary> updateVocabulary(Vocabulary vocabulary) {
});
}

@Override
public Vocabulary getDefaultVocabulary() {
try (var connection = getConnection()) {
var querySpec = QuerySpec.Builder.newInstance().filter(criterion("default_vocabulary", "=", true)).build();
var statement = vocabularyStatements.createQuery(querySpec);
return queryExecutor.query(connection, true, this::mapVocabulary, statement.getQueryAsString(), statement.getParameters())
.findFirst().orElse(null);
} catch (SQLException e) {
throw new EdcPersistenceException(e);
}
}

private int mapRowCount(ResultSet resultSet) throws SQLException {
return resultSet.getInt(vocabularyStatements.getCountVariableName());
}
Expand All @@ -167,7 +152,6 @@ private Vocabulary mapVocabulary(ResultSet resultSet) throws SQLException {
.createdAt(resultSet.getLong(vocabularyStatements.getCreatedAtColumn()))
.name(resultSet.getString(vocabularyStatements.getNameColumn()))
.category(resultSet.getString(vocabularyStatements.getCategoryColumn()))
.defaultVocabulary(resultSet.getBoolean(vocabularyStatements.getDefaultVocabularyColumn()))
.jsonSchema(resultSet.getString(vocabularyStatements.getJsonSchemaColumn()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.upm.inesdata.vocabulary.sql.index.schema;

import org.upm.inesdata.vocabulary.sql.index.schema.postgres.VocabularyMapping;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.sql.translation.SqlOperatorTranslator;
import org.eclipse.edc.sql.translation.SqlQueryStatement;
import org.upm.inesdata.vocabulary.sql.index.schema.postgres.VocabularyMapping;

import static java.lang.String.format;

Expand All @@ -25,7 +25,6 @@ public String getInsertVocabularyTemplate() {
.column(getCreatedAtColumn())
.column(getNameColumn())
.column(getCategoryColumn())
.column(getDefaultVocabularyColumn())
.jsonColumn(getJsonSchemaColumn())
.insertInto(getVocabularyTable());
}
Expand All @@ -36,7 +35,6 @@ public String getUpdateVocabularyTemplate() {
.column(getNameColumn())
.jsonColumn(getJsonSchemaColumn())
.column(getCategoryColumn())
.column(getDefaultVocabularyColumn())
.update(getVocabularyTable(), getVocabularyIdColumn());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ default String getCategoryColumn() {
return "category";
}

default String getDefaultVocabularyColumn() {
return "default_vocabulary";
}

default String getCreatedAtColumn() {
return "created_at";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public VocabularyMapping(VocabularyStatements statements) {
add("createdAt", statements.getCreatedAtColumn());
add("name", statements.getNameColumn());
add("category", statements.getCategoryColumn());
add("default_vocabulary", statements.getDefaultVocabularyColumn());
add("json_schema", new JsonFieldTranslator(statements.getJsonSchemaColumn()));
}

Expand Down
3 changes: 1 addition & 2 deletions resources/sql/vocabulary-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ CREATE TABLE IF NOT EXISTS edc_vocabulary
created_at BIGINT NOT NULL,
json_schema JSON DEFAULT '{}',
name VARCHAR NOT NULL,
category VARCHAR NOT NULL,
default_vocabulary BOOLEAN DEFAULT FALSE,
category VARCHAR NOT NULL
PRIMARY KEY (id)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.upm.inesdata.spi.vocabulary;

import org.upm.inesdata.spi.vocabulary.domain.Vocabulary;
import org.eclipse.edc.runtime.metamodel.annotation.ExtensionPoint;
import org.eclipse.edc.spi.persistence.EdcPersistenceException;
import org.eclipse.edc.spi.result.StoreResult;
import org.upm.inesdata.spi.vocabulary.domain.Vocabulary;

import java.util.stream.Stream;

Expand Down Expand Up @@ -58,12 +58,4 @@ public interface VocabularyIndex {
*/
StoreResult<Vocabulary> updateVocabulary(Vocabulary vocabulary);

/**
* Fetches the default {@link Vocabulary} from the metadata backend.
*
* @return The {@link Vocabulary} if one was found, or null otherwise.
* @throws NullPointerException If {@code vocabularyId} was null or empty.
*/
Vocabulary getDefaultVocabulary();

}
Loading

0 comments on commit 8bb6b93

Please sign in to comment.