@Test public void testInsertNotNested() { final DataType dataType = mock(DataType.class); final DataType reference = mock(DataType.class); final ItemDefinition itemDefinition = mock(ItemDefinition.class); final List<DataType> expectedAffectedDataTypes = asList(mock(DataType.class), mock(DataType.class)); final CreationType creationType = ABOVE; doReturn(expectedAffectedDataTypes).when(handler).insertSibling(dataType, reference, creationType, itemDefinition); final List<DataType> actualAffectedDataTypes = handler.insertSibling(dataType, reference, creationType, itemDefinition); assertEquals(expectedAffectedDataTypes, actualAffectedDataTypes); }
public List<DataType> insertSibling(final DataType dataType, final DataType reference, final CreationType creationType, final ItemDefinition itemDefinition) { final Optional<DataType> parentOptional = lookupAbsoluteParent(reference); if (parentOptional.isPresent()) { final DataType parent = parentOptional.get(); final List<DataType> siblings = parent.getSubDataTypes(); final DataType updatedDataType = updateDataTypeProperties(dataType, parent.getUUID(), itemDefinition); final DataType parentReference = findParentReference(reference, siblings); siblings.add(siblings.indexOf(parentReference) + creationType.getIndexIncrement(), updatedDataType); recordEngine.doUpdate(dataType, itemDefinition); return recordEngine.update(parent); } else { final DataType updatedDataType = updateDataTypeProperties(dataType, reference.getParentUUID(), itemDefinition); recordEngine.doUpdate(updatedDataType, itemDefinition); return new ArrayList<>(); } }
DataTypeCreateHandler extends DataTypeHandler { public List<DataType> insertSibling(final DataType dataType, final DataType reference, final CreationType creationType, final ItemDefinition itemDefinition) { final Optional<DataType> parentOptional = lookupAbsoluteParent(reference); if (parentOptional.isPresent()) { final DataType parent = parentOptional.get(); final List<DataType> siblings = parent.getSubDataTypes(); final DataType updatedDataType = updateDataTypeProperties(dataType, parent.getUUID(), itemDefinition); final DataType parentReference = findParentReference(reference, siblings); siblings.add(siblings.indexOf(parentReference) + creationType.getIndexIncrement(), updatedDataType); recordEngine.doUpdate(dataType, itemDefinition); return recordEngine.update(parent); } else { final DataType updatedDataType = updateDataTypeProperties(dataType, reference.getParentUUID(), itemDefinition); recordEngine.doUpdate(updatedDataType, itemDefinition); return new ArrayList<>(); } } }
DataTypeCreateHandler extends DataTypeHandler { public List<DataType> insertSibling(final DataType dataType, final DataType reference, final CreationType creationType, final ItemDefinition itemDefinition) { final Optional<DataType> parentOptional = lookupAbsoluteParent(reference); if (parentOptional.isPresent()) { final DataType parent = parentOptional.get(); final List<DataType> siblings = parent.getSubDataTypes(); final DataType updatedDataType = updateDataTypeProperties(dataType, parent.getUUID(), itemDefinition); final DataType parentReference = findParentReference(reference, siblings); siblings.add(siblings.indexOf(parentReference) + creationType.getIndexIncrement(), updatedDataType); recordEngine.doUpdate(dataType, itemDefinition); return recordEngine.update(parent); } else { final DataType updatedDataType = updateDataTypeProperties(dataType, reference.getParentUUID(), itemDefinition); recordEngine.doUpdate(updatedDataType, itemDefinition); return new ArrayList<>(); } } @Inject  DataTypeCreateHandler(final DataTypeStore dataTypeStore,
                                 final DataTypeManager dataTypeManager); }
DataTypeCreateHandler extends DataTypeHandler { public List<DataType> insertSibling(final DataType dataType, final DataType reference, final CreationType creationType, final ItemDefinition itemDefinition) { final Optional<DataType> parentOptional = lookupAbsoluteParent(reference); if (parentOptional.isPresent()) { final DataType parent = parentOptional.get(); final List<DataType> siblings = parent.getSubDataTypes(); final DataType updatedDataType = updateDataTypeProperties(dataType, parent.getUUID(), itemDefinition); final DataType parentReference = findParentReference(reference, siblings); siblings.add(siblings.indexOf(parentReference) + creationType.getIndexIncrement(), updatedDataType); recordEngine.doUpdate(dataType, itemDefinition); return recordEngine.update(parent); } else { final DataType updatedDataType = updateDataTypeProperties(dataType, reference.getParentUUID(), itemDefinition); recordEngine.doUpdate(updatedDataType, itemDefinition); return new ArrayList<>(); } } @Inject  DataTypeCreateHandler(final DataTypeStore dataTypeStore,
                                 final DataTypeManager dataTypeManager); List<DataType> append(final DataType dataType,
                                 final ItemDefinition itemDefinition); List<DataType> insertSibling(final DataType dataType,
                                        final DataType reference,
                                        final CreationType creationType,
                                        final ItemDefinition itemDefinition); List<DataType> insertNested(final DataType dataType,
                                       final DataType reference,
                                       final ItemDefinition itemDefinition); }
DataTypeCreateHandler extends DataTypeHandler { public List<DataType> insertSibling(final DataType dataType, final DataType reference, final CreationType creationType, final ItemDefinition itemDefinition) { final Optional<DataType> parentOptional = lookupAbsoluteParent(reference); if (parentOptional.isPresent()) { final DataType parent = parentOptional.get(); final List<DataType> siblings = parent.getSubDataTypes(); final DataType updatedDataType = updateDataTypeProperties(dataType, parent.getUUID(), itemDefinition); final DataType parentReference = findParentReference(reference, siblings); siblings.add(siblings.indexOf(parentReference) + creationType.getIndexIncrement(), updatedDataType); recordEngine.doUpdate(dataType, itemDefinition); return recordEngine.update(parent); } else { final DataType updatedDataType = updateDataTypeProperties(dataType, reference.getParentUUID(), itemDefinition); recordEngine.doUpdate(updatedDataType, itemDefinition); return new ArrayList<>(); } } @Inject  DataTypeCreateHandler(final DataTypeStore dataTypeStore,
                                 final DataTypeManager dataTypeManager); List<DataType> append(final DataType dataType,
                                 final ItemDefinition itemDefinition); List<DataType> insertSibling(final DataType dataType,
                                        final DataType reference,
                                        final CreationType creationType,
                                        final ItemDefinition itemDefinition); List<DataType> insertNested(final DataType dataType,
                                       final DataType reference,
                                       final ItemDefinition itemDefinition);  }