Package org.openengsb.core.edb.api

Examples of org.openengsb.core.edb.api.EDBObject


        map.put("keyB", "valueB");
        TestModel model = new TestModel();
        model.setId("test");
        model.setMap(map);
        ConnectorInformation id = getTestConnectorInformation();
        EDBObject object = converter.convertModelToEDBObject(model, id).get(0);

        assertThat(object.getString(EDBConverter.getEntryNameForMapKey("map", 0)), is("keyA"));
        assertThat(object.getString(EDBConverter.getEntryNameForMapValue("map", 0)), is("valueA"));
        assertThat(object.getString(EDBConverter.getEntryNameForMapKey("map", 1)), is("keyB"));
        assertThat(object.getString(EDBConverter.getEntryNameForMapValue("map", 1)), is("valueB"));
    }
View Full Code Here


        model.setId("test");
        Date date = new Date();
        model.setDate(date);
        model.setEnumeration(ENUM.A);
        model.setName("testobject");
        EDBObject object = converter.convertModelToEDBObject(model, getTestConnectorInformation()).get(0);
        TestModel result = converter.convertEDBObjectToModel(TestModel.class, object);

        assertThat(model.getId(), is(result.getId()));
        assertThat(model.getDate(), is(result.getDate()));
        assertThat(model.getEnumeration(), is(result.getEnumeration()));
View Full Code Here

    @Test
    public void testIfArraysAreSupported_shouldWork() throws Exception {
        TestModel model = new TestModel();
        Integer[] numbers = new Integer[]{ 1, 2, 3, 4 };
        model.setNumbers(numbers);
        EDBObject object = converter.convertModelToEDBObject(model, getTestConnectorInformation()).get(0);
        TestModel result = converter.convertEDBObjectToModel(TestModel.class, object);

        assertThat(result.getNumbers(), notNullValue());
        assertThat(numbers[0], is(result.getNumbers()[0]));
        assertThat(numbers[1], is(result.getNumbers()[1]));
View Full Code Here

        assertThat(numbers[3], is(result.getNumbers()[3]));
    }

    @Test
    public void testEDBObjectToModelConversion_shouldWork() throws Exception {
        EDBObject object = new EDBObject("test");
        object.putEDBObjectEntry(EDBConstants.MODEL_TYPE, TestModel.class.getName());
        object.putEDBObjectEntry(EDBConstants.MODEL_OID, "test");
        object.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1));
        object.putEDBObjectEntry("id", "test");
        object.putEDBObjectEntry("name", "testname");
        object.putEDBObjectEntry("number", 42);
        object.putEDBObjectEntry("check", false);
        object.putEDBObjectEntry("check2", true);
        TestModel model = converter.convertEDBObjectToModel(TestModel.class, object);
        assertThat(model.getId(), is("test"));
        assertThat(model.getName(), is("testname"));
        assertThat(model.isCheck(), is(false));
        assertThat(model.isCheck2(), is(true));
View Full Code Here

    }

    @Test
    public void testEDBObjectToRecursiveModelConversion_shouldWork() throws Exception {
        // prepare
        EDBObject root = new EDBObject("root");
        root.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName());
        root.putEDBObjectEntry(EDBConstants.MODEL_OID, "root");
        root.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1));
        root.putEDBObjectEntry("id", "root");
        root.putEDBObjectEntry("child", "child1");

        EDBObject child1 = new EDBObject("child1");
        child1.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName());
        child1.putEDBObjectEntry(EDBConstants.MODEL_OID, "child1");
        child1.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1));
        child1.putEDBObjectEntry("id", "child1");
        child1.putEDBObjectEntry("child", "child2");

        EDBObject child2 = new EDBObject("child2");
        child2.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName());
        child2.putEDBObjectEntry(EDBConstants.MODEL_OID, "child2");
        child2.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1));
        child2.putEDBObjectEntry("id", "child2");
        child2.putEDBObjectEntry("child", "child3");

        EDBObject child3 = new EDBObject("child3");
        child3.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName());
        child3.putEDBObjectEntry(EDBConstants.MODEL_OID, "child3");
        child3.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1));
        child3.putEDBObjectEntry("id", "child3");

        when(mockedService.getObject(eq("child1"), anyLong())).thenReturn(child1);
        when(mockedService.getObject(eq("child2"), anyLong())).thenReturn(child2);
        when(mockedService.getObject(eq("child3"), anyLong())).thenReturn(child3);
View Full Code Here

                    time = Long.parseLong(timestamp.toString());
                } catch (NumberFormatException e) {
                    LOGGER.warn("The model with the oid {} has an invalid timestamp.", object.getOID());
                }
            }
            EDBObject obj = edbService.getObject((String) value, time);
            value = convertEDBObjectToUncheckedModel(parameterType, obj);
            object.remove(propertyName);
        } else if (parameterType.equals(FileWrapper.class)) {
            FileWrapper wrapper = new FileWrapper();
            String filename = object.getString(propertyName + FILEWRAPPER_FILENAME_SUFFIX);
View Full Code Here

     * Recursive function to generate a list of EDBObjects out of a model object.
     */
    private String convertSubModel(OpenEngSBModel model, List<EDBObject> objects, ConnectorInformation info) {
        String contextId = ContextHolder.get().getCurrentContextId();
        String oid = ModelWrapper.wrap(model).getCompleteModelOID();
        EDBObject object = new EDBObject(oid);
        try {
            fillEDBObjectWithEngineeringObjectInformation(object, model);
        } catch (IllegalAccessException e) {
            LOGGER.warn("Unable to fill completely the EngineeringObjectInformation into the EDBObject", e);
            throw new EKBException("Unable to fill completely the EngineeringObjectInformation into the EDBObject", e);
        }
        for (OpenEngSBModelEntry entry : model.toOpenEngSBModelEntries()) {
            if (entry.getValue() == null) {
                continue;
            } else if (entry.getType().equals(FileWrapper.class)) {
                try {
                    FileWrapper wrapper = (FileWrapper) entry.getValue();
                    String content = Base64.encodeBase64String(wrapper.getContent());
                    object.putEDBObjectEntry(entry.getKey(), content, String.class);
                    object.putEDBObjectEntry(entry.getKey() + FILEWRAPPER_FILENAME_SUFFIX,
                        wrapper.getFilename(), String.class);
                } catch (IOException e) {
                    LOGGER.error(e.getMessage());
                }
            } else if (OpenEngSBModel.class.isAssignableFrom(entry.getType())) {
                OpenEngSBModel temp = (OpenEngSBModel) entry.getValue();
                String subOid = convertSubModel(temp, objects, info);
                object.putEDBObjectEntry(entry.getKey(), subOid, String.class);
            } else if (List.class.isAssignableFrom(entry.getType())) {
                List<?> list = (List<?>) entry.getValue();
                if (list == null || list.size() == 0) {
                    continue;
                }
                Boolean modelItems = null;
                for (int i = 0; i < list.size(); i++) {
                    Object item = list.get(i);
                    if (modelItems == null) {
                        modelItems = OpenEngSBModel.class.isAssignableFrom(item.getClass());
                    }
                    if (modelItems) {
                        item = convertSubModel((OpenEngSBModel) item, objects, info);
                    }
                    String entryName = getEntryNameForList(entry.getKey(), i);
                    object.putEDBObjectEntry(entryName, item, item.getClass());
                }
            } else if (entry.getType().isArray()) {
                Object[] array = (Object[]) entry.getValue();
                if (array == null || array.length == 0) {
                    continue;
                }
                Boolean modelItems = null;
                for (int i = 0; i < array.length; i++) {
                    Object item = array[i];
                    if (modelItems == null) {
                        modelItems = OpenEngSBModel.class.isAssignableFrom(item.getClass());
                    }
                    if (modelItems) {
                        item = convertSubModel((OpenEngSBModel) item, objects, info);
                    }
                    String entryName = getEntryNameForList(entry.getKey(), i);
                    object.putEDBObjectEntry(entryName, item, item.getClass());
                }
            } else if (Map.class.isAssignableFrom(entry.getType())) {
                Map<?, ?> map = (Map<?, ?>) entry.getValue();
                if (map == null || map.size() == 0) {
                    continue;
                }
                Boolean keyIsModel = null;
                Boolean valueIsModel = null;
                int i = 0;
                for (Map.Entry<?, ?> ent : map.entrySet()) {
                    if (keyIsModel == null) {
                        keyIsModel = OpenEngSBModel.class.isAssignableFrom(ent.getKey().getClass());
                    }
                    if (valueIsModel == null) {
                        valueIsModel = OpenEngSBModel.class.isAssignableFrom(ent.getValue().getClass());
                    }
                    Object key = ent.getKey();
                    Object value = ent.getValue();
                    if (keyIsModel) {
                        key = convertSubModel((OpenEngSBModel) key, objects, info);
                    }
                    if (valueIsModel) {
                        value = convertSubModel((OpenEngSBModel) value, objects, info);
                    }
                    object.putEDBObjectEntry(getEntryNameForMapKey(entry.getKey(), i), key);
                    object.putEDBObjectEntry(getEntryNameForMapValue(entry.getKey(), i), value);
                    i++;
                }
            } else {
                object.putEDBObjectEntry(entry.getKey(), entry.getValue(), entry.getType());
            }
        }
        object.putEDBObjectEntry(EDBConstants.MODEL_TYPE, model.retrieveModelName());
        object.putEDBObjectEntry(EDBConstants.MODEL_TYPE_VERSION, model.retrieveModelVersion());
        object.putEDBObjectEntry("domainId", info.getDomainId());
        object.putEDBObjectEntry("connectorId", info.getConnectorId());
        object.putEDBObjectEntry("instanceId", info.getInstanceId());
        object.putEDBObjectEntry("contextId", contextId);
        objects.add(object);
        return oid;
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testDeleteCommit_shouldDeleteCommit() throws Exception {
        UUID preCommit1Revision = db.getCurrentRevisionNumber();
        EDBObject eo1 = createRandomTestObject("deleteCommitTest/1");
        EDBObject eo2 = createRandomTestObject("deleteCommitTest/2");
        commitObjects(Lists.newArrayList(eo1, eo2), null, null);

        UUID preCommit2Revision = db.getCurrentRevisionNumber();
        EDBObject eo3 = createRandomTestObject("deleteCommitTest/3");
        commitObjects(Lists.newArrayList(eo3), null, Lists.newArrayList(eo1, eo2));

        UUID postCommit2Revision = db.getCurrentRevisionNumber();
        List<EDBObject> result = db.query(QueryRequest.create());
        assertThat(result.size(), is(1));
View Full Code Here

     * state and the list of elements from the end state is taken.
     */
    private void addModifiedOrDeletedObjects(List<EDBObject> tempList) {
        for (EDBObject a : this.startState) {
            String oid = a.getOID();
            EDBObject b = removeIfExist(oid, tempList);
            ObjectDiff odiff = new ObjectDiff(this.startCommit, this.endCommit, a, b);
            if (odiff.getDifferenceCount() > 0) {
                diff.put(oid, odiff);
            }
        }
View Full Code Here

     * returned.
     */
    private EDBObject removeIfExist(String oid, List<EDBObject> tempList) {
        Iterator<EDBObject> iterator = tempList.iterator();
        while (iterator.hasNext()) {
            EDBObject obj = iterator.next();
            if (obj.getOID().equals(oid)) {
                iterator.remove();
                return obj;
            }
        }
        LOGGER.debug(oid + " wasn't found in the list of end state objects");
View Full Code Here

TOP

Related Classes of org.openengsb.core.edb.api.EDBObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.