blob: 7d6e6548064c1da6ac9b63a2aeab805421d89a65 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.unomi.api.services;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.unomi.api.Metadata;
import org.apache.unomi.api.PartialList;
import org.apache.unomi.api.schema.json.JSONSchema;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* Service that allow to manage JSON schema. It allows to get, save and delete schemas
*/
public interface SchemaService {
/**
* Retrieves json schema metadatas, ordered according to the specified {@code sortBy} String and and paged: only {@code size} of them
* are retrieved, starting with the {@code
* offset}-th one.
*
* @param offset zero or a positive integer specifying the position of the first element in the total ordered collection of matching elements
* @param size a positive integer specifying how many matching elements should be retrieved or {@code -1} if all of them should be retrieved
* @param sortBy an optional ({@code null} if no sorting is required) String of comma ({@code ,}) separated property names on which ordering should be performed, ordering elements according to the property order in the
* String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
* a column ({@code :}) and an order specifier: {@code asc} or {@code desc}.
* @return a {@link PartialList} of json schema metadata
*/
PartialList<Metadata> getJsonSchemaMetadatas(int offset, int size, String sortBy);
/**
* Verify if a jsonNode is valid against a schema
*
* @param jsonNode to validate
* @param schemaId id of the schema used for the validation
* @return true is the object is valid
*/
boolean isValid(JsonNode jsonNode, String schemaId);
/**
* Get a schema matching by a schema id
*
* @param schemaId Id of the schema
* @return A JSON schema
*/
JSONSchema getSchema(String schemaId);
/**
* Get a list a {@link org.apache.unomi.api.schema.json.JSONSchema}
*
* @param target to filter the schemas
* @return a list of JSONSchema
*/
List<JSONSchema> getSchemasByTarget(String target);
/**
* Save a new schema or update a schema
*
* @param schema as a String value
*/
void saveSchema(String schema);
/**
* Save a new schema or update a schema
*
* @param schemaStream inputStream of the schema
*/
void saveSchema(InputStream schemaStream) throws IOException;
/**
* Load a predefined schema into memory
*
* @param schemaStream inputStream of the schema
*/
void loadPredefinedSchema(InputStream schemaStream);
/**
* Delete a schema according to its id
*
* @param schemaId id of the schema to delete
* @return true if the schema has been deleted
*/
boolean deleteSchema(String schemaId);
/**
* Delete a schema
*
* @param schemaStream inputStream of the schema to delete
* @return true if the schema has been deleted
*/
boolean deleteSchema(InputStream schemaStream);
/**
* Save an extension of a JSON schema
*
* @param extensionStream inputStream of the extension
*/
void saveExtension(InputStream extensionStream) throws IOException;
/**
* Save an extension of a JSON schema
*
* @param extension as String value
*/
void saveExtension(String extension) throws IOException;
/**
* Delete an extension
*
* @param extensionStream inputStream of the extension to delete
* @return true if the extension has been deleted
*/
boolean deleteExtension(InputStream extensionStream) throws IOException;
/**
* Delete an extension by an id
*
* @param extensionId id of the extension
* @return true if the extension has been deleted
*/
boolean deleteExtension(String extensionId);
/**
* Retrieves json schema extension metadatas, ordered according to the specified {@code sortBy} String and and paged: only {@code size}
* of them
* are retrieved, starting with the {@code
* offset}-th one.
*
* @param offset zero or a positive integer specifying the position of the first element in the total ordered collection of matching elements
* @param size a positive integer specifying how many matching elements should be retrieved or {@code -1} if all of them should be retrieved
* @param sortBy an optional ({@code null} if no sorting is required) String of comma ({@code ,}) separated property names on which ordering should be performed, ordering elements according to the property order in the
* String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
* a column ({@code :}) and an order specifier: {@code asc} or {@code desc}.
* @return a {@link PartialList} of json schema extension metadata
*/
PartialList<Metadata> getJsonSchemaExtensionsMetadatas(int offset, int size, String sortBy);
}