AttributeService { public InternalFeature getAttributes(VectorLayer layer, InternalFeature feature, Object featureBean) throws LayerException { String layerId = layer.getId(); Map<String, Attribute> featureAttributes = getRealAttributes(layer, featureBean); feature.setAttributes(featureAttributes); addSyntheticAttributes(feature, featureAttributes, layer); if (securityContext.isFeatureVisible(layerId, feature)) { feature.setAttributes(filterAttributes(layerId, layer.getLayerInfo().getFeatureInfo().getAttributesMap(), feature, featureAttributes)); feature.setEditable(securityContext.isFeatureUpdateAuthorized(layerId, feature)); feature.setDeletable(securityContext.isFeatureDeleteAuthorized(layerId, feature)); return feature; } return null; }  InternalFeature getAttributes(VectorLayer layer, InternalFeature feature, Object featureBean); void setAttributeEditable(Attribute attribute, boolean editable);  }
@Test public void testNormal() throws Exception { InternalFeature feature = new InternalFeatureImpl(); Assert.assertNotNull(attributeService.getAttributes(layerBeans, feature, featureBean)); Attribute attribute; Attribute linked; attribute = feature.getAttributes().get("stringAttr"); assertThat(attribute.getValue()).isEqualTo(TEST_STRING); assertThat(attribute.isEditable()).isTrue(); attribute = feature.getAttributes().get("integerAttr"); assertThat(attribute.getValue()).isEqualTo(TEST_INTEGER); assertThat(attribute.isEditable()).isTrue(); attribute = feature.getAttributes().get("booleanAttr"); assertThat(attribute.getValue()).isEqualTo(Boolean.TRUE); assertThat(attribute.isEditable()).isTrue(); assertThat(containsLazy(feature.getAttributes())).isFalse(); Feature dto = dtoConverter.toDto(feature); assertThat(containsLazy(dto.getAttributes())).isFalse(); attribute = feature.getAttributes().get("manyToOneAttr"); assertThat(attribute.isEditable()).isTrue(); linked = ((ManyToOneAttribute) attribute).getValue().getAllAttributes().get("stringAttr"); assertThat(linked.getValue()).isEqualTo(TEST_STRING2); assertThat(linked.isEditable()).isTrue(); attribute = feature.getAttributes().get("oneToManyAttr"); assertThat(attribute.isEditable()).isTrue(); linked = ((OneToManyAttribute) attribute).getValue().get(0).getAllAttributes().get("stringAttr"); assertThat(linked.getValue()).isEqualTo(TEST_STRING3); assertThat(linked.isEditable()).isTrue(); }
@Test @DirtiesContext public void testLazy() throws Exception { InternalFeature feature = new InternalFeatureImpl(); Assert.assertNotNull(attributeService.getAttributes(lazyLayerBeans, feature, featureBean)); Attribute attribute; Attribute linked; attribute = feature.getAttributes().get("stringAttr"); assertThat(attribute.getValue()).isEqualTo(TEST_STRING); assertThat(attribute.isEditable()).isTrue(); attribute = feature.getAttributes().get("integerAttr"); assertThat(attribute.getValue()).isEqualTo(TEST_INTEGER); assertThat(attribute.isEditable()).isTrue(); attribute = feature.getAttributes().get("booleanAttr"); assertThat(attribute.getValue()).isEqualTo(Boolean.TRUE); assertThat(attribute.isEditable()).isTrue(); assertThat(containsLazy(feature.getAttributes())).isTrue(); Feature dto = dtoConverter.toDto(feature); assertThat(containsLazy(dto.getAttributes())).isFalse(); attribute = feature.getAttributes().get("manyToOneAttr"); assertThat(attribute.isEditable()).isTrue(); linked = ((ManyToOneAttribute) attribute).getValue().getAllAttributes().get("stringAttr"); assertThat(linked.getValue()).isEqualTo(TEST_STRING2); assertThat(linked.isEditable()).isTrue(); attribute = feature.getAttributes().get("oneToManyAttr"); assertThat(attribute.isEditable()).isTrue(); linked = ((OneToManyAttribute) attribute).getValue().get(0).getAllAttributes().get("stringAttr"); assertThat(linked.getValue()).isEqualTo(TEST_STRING3); assertThat(linked.isEditable()).isTrue(); }