Skip to content

Package: ModelContext

ModelContext

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.elasticsearch.client;
14:
15: import org.eclipse.kapua.service.elasticsearch.client.exception.DatamodelMappingException;
16:
17: import java.util.Map;
18:
19: /**
20: * {@link ModelContext} definition.
21: * <p>
22: * This object is responsible for translating document model objects from/to client objects
23: *
24: * @since 1.0.0
25: */
26: public interface ModelContext {
27:
28: /**
29: * Type descriptor key
30: *
31: * @since 1.0.0
32: */
33: String TYPE_DESCRIPTOR_KEY = "type_descriptor";
34:
35: /**
36: * Converts the serialized object (from client domain) to the specific Elasticsearch object.
37: *
38: * @param clazz The client object type
39: * @param serializedObject The serialized objetc as {@link Map}
40: * @return The object
41: * @throws DatamodelMappingException if there are error in resource mapping.
42: * @since 1.0.0
43: */
44: <T> T unmarshal(Class<T> clazz, Map<String, Object> serializedObject) throws DatamodelMappingException;
45:
46: /**
47: * Converts the Elasticsearch object to the client object
48: *
49: * @param object The object to convert.
50: * @return The converted object as a {@link Map}
51: * @throws DatamodelMappingException if there are error in resource mapping.
52: * @since 1.0.0
53: */
54: Map<String, Object> marshal(Object object) throws DatamodelMappingException;
55:
56: /**
57: * Gets the key name of the id field.
58: *
59: * @return The key name of the id field.
60: * @since 1.3.0
61: */
62: String getIdKeyName();
63:
64: }