public static RevFeatureType readFeatureType(ObjectId id, DataInput in, FeatureTypeFactory typeFactory) throws IOException { Name name = readName(in); int propertyCount = in.readInt(); List<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>(); for (int i = 0; i < propertyCount; i++) { attributes.add(readAttributeDescriptor(in, typeFactory)); } SimpleFeatureType ftype = typeFactory.createSimpleFeatureType(name, attributes, null, false, Collections.<Filter> emptyList(), BasicFeatureTypes.FEATURE, null); return RevFeatureType.builder().id(id).type(ftype).build(); }
public static RevFeatureTypeBuilder builder() { return new RevFeatureTypeBuilder(); } }
/** * Builds a {@link RevFeatureType} for the given feature type, computing its id throuh * {@link HashObject} */ public RevFeatureType build() { return build(id, type); }
private Iterator<Feature> transformFeatures(SimpleFeatureType featureType, String path) { String refspec = Ref.WORK_HEAD + ":" + path; Iterator<NodeRef> oldFeatures = command(LsTreeOp.class).setReference(refspec) .setStrategy(Strategy.FEATURES_ONLY).call(); RevFeatureType revFeatureType = RevFeatureType.builder().type(featureType).build(); Iterator<Feature> transformedIterator = transformIterator(oldFeatures, revFeatureType); return transformedIterator; }
public RevFeatureType readFeatureType(@Nullable ObjectId id, DataInput in, FeatureTypeFactory typeFactory) throws IOException { Name name = readName(in); int propertyCount = readUnsignedVarInt(in); List<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>(); for (int i = 0; i < propertyCount; i++) { attributes.add(readAttributeDescriptor(in, typeFactory)); } SimpleFeatureType ftype = typeFactory.createSimpleFeatureType(name, attributes, null, false, Collections.<Filter> emptyList(), BasicFeatureTypes.FEATURE, null); return RevFeatureType.builder().id(id).type(ftype).build(); }
RevFeatureType revFeatureType = RevFeatureTypeBuilder.build(featureType); List<PropertyDescriptor> descriptors = revFeatureType.descriptors(); for (int i = 0; i < descriptors.size(); i++) {
@Override protected RevFeatureType read(@Nullable ObjectId id, BufferedReader reader, TYPE type) throws IOException { Preconditions.checkArgument(TYPE.FEATURETYPE.equals(type), "Wrong type: %s", type.name()); builder = new SimpleFeatureTypeBuilder(); typeFactory = builder.getFeatureTypeFactory(); String name = parseLine(requireLine(reader), "name"); SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); if (name.contains(":")) { int idx = name.lastIndexOf(':'); String namespace = name.substring(0, idx); String local = name.substring(idx + 1); builder.setName(new NameImpl(namespace, local)); } else { builder.setName(new NameImpl(name)); } String line; while ((line = reader.readLine()) != null) { builder.add(parseAttributeDescriptor(line)); } SimpleFeatureType sft = builder.buildFeatureType(); return RevFeatureType.builder().id(id).type(sft).build(); }
@Test public void testGet() throws Exception { ObjectId meta1 = getOID(1); ObjectId meta2 = getOID(2); SimpleFeatureType fType1 = DataUtilities.createType("location", "the_geom:Point:srid=4326,name:String,name2:String"); RevFeatureType revft1 = RevFeatureType.builder().id(getOID(1)).type(fType1).build(); SimpleFeatureType fType2 = DataUtilities.createType("location", "the_geom:Point:srid=4326,name3:String,name4:String"); RevFeatureType revft2 = RevFeatureType.builder().id(getOID(1)).type(fType2).build(); ObjectDatabase odb = mock(ObjectDatabase.class); when(odb.getFeatureType(meta1)).thenReturn(revft1); when(odb.getFeatureType(meta2)).thenReturn(revft2); MultiFeatureTypeBuilder builder = new MultiFeatureTypeBuilder(odb); FeatureBuilder fb1 = builder.get(meta1); FeatureBuilder fb2 = builder.get(meta2); Assert.isTrue(fb1 == builder.get(meta1)); // not rebuilt Assert.isTrue(fb2 == builder.get(meta2)); // not rebuilt Assert.isTrue(fb1.getType().equals(revft1)); Assert.isTrue(fb2.getType().equals(revft2)); }
@Test public void testBuild() throws Exception { ObjectId meta1 = getOID(1); SimpleFeatureType fType1 = DataUtilities.createType("location", "the_geom:Point:srid=4326,name:String,name2:String"); RevFeatureType revft1 = RevFeatureType.builder().id(getOID(1)).type(fType1).build(); ObjectDatabase odb = mock(ObjectDatabase.class); when(odb.getFeatureType(meta1)).thenReturn(revft1); WKTReader2 wkt = new WKTReader2(); RevFeature feat = RevObjectTestSupport.feature(wkt.read("POINT(0 0)"), "abc", "def"); Node n1 = RevObjectFactory.defaultInstance().createNode("name1", getOID(2), meta1, TYPE.FEATURE, new Envelope(), null); NodeRef nr1 = new NodeRef(n1, "testcase", meta1); ObjectInfo<RevFeature> fi = ObjectInfo.of(nr1, feat); MultiFeatureTypeBuilder builder = new MultiFeatureTypeBuilder(odb); SimpleFeature sf = builder.apply(fi); Assert.isTrue(sf.getAttribute("name").equals("abc")); Assert.isTrue(sf.getAttribute("name2").equals("def")); }
@Override protected void setUpInternal() throws Exception { insertAndAdd(points1, points2, points3); commit("inital"); SimpleFeatureType fullSchema = pointsType; RevFeatureType nativeType = RevFeatureType.builder().type(fullSchema).build(); Context actualContext = repo.context(); context = spy(actualContext); difftree = spy(context.command(DiffTree.class)); doReturn(difftree).when(context).command(eq(DiffTree.class)); NodeRef typeRef = context.workingTree().getFeatureTypeTrees().get(0); FeatureReaderBuilder b = FeatureReaderBuilder.builder(context, nativeType, typeRef); builder = spy(b); }
@Test public void testModifiedEmptyFeatureTypePatch() throws Exception { Patch patch = new Patch(); RevFeatureType featureType = RevFeatureType.builder().type(pointsType).build(); RevFeatureType modifiedFeatureType = RevFeatureType.builder().type(modifiedPointsType) .build(); patch.addFeatureType(featureType); patch.addFeatureType(modifiedFeatureType); patch.addAlteredTree( new FeatureTypeDiff(pointsName, featureType.getId(), modifiedFeatureType.getId())); testPatch(patch); }
@Test public void testAddFeatureAttributePatch() throws Exception { Patch patch = new Patch(); String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID()); Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap(); Object newValue = points1B.getProperty("extra").getValue(); GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(null, newValue); map.put(modifiedPointsType.getDescriptor("extra"), diff); FeatureDiff featureDiff = new FeatureDiff(path, map, RevFeatureType.builder().type(pointsType).build(), RevFeatureType.builder().type(modifiedPointsType).build()); patch.addModifiedFeature(featureDiff); patch.addFeatureType(RevFeatureType.builder().type(modifiedPointsType).build()); testPatch(patch); }