use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class BlameOp method _call.
@Override
protected BlameReport _call() {
String fullPath = (commit != null ? commit.toString() : Ref.HEAD) + ":" + path;
Optional<ObjectId> id = command(RevParse.class).setRefSpec(fullPath).call();
if (!id.isPresent()) {
throw new BlameException(StatusCode.FEATURE_NOT_FOUND);
}
TYPE type = command(ResolveObjectType.class).setObjectId(id.get()).call();
if (!type.equals(TYPE.FEATURE)) {
throw new BlameException(StatusCode.PATH_NOT_FEATURE);
}
Optional<RevFeatureType> featureType = command(ResolveFeatureType.class).setRefSpec(path).call();
BlameReport report = new BlameReport(featureType.get());
Iterator<RevCommit> log = command(LogOp.class).addPath(path).setUntil(commit).call();
RevCommit commit = log.next();
RevObjectParse revObjectParse = command(RevObjectParse.class);
DiffOp diffOp = command(DiffOp.class);
DiffFeature diffFeature = command(DiffFeature.class);
while (!report.isComplete()) {
if (!log.hasNext()) {
String refSpec = commit.getId().toString() + ":" + path;
RevFeature feature = revObjectParse.setRefSpec(refSpec).call(RevFeature.class).get();
report.setFirstVersion(feature, commit);
break;
}
RevCommit commitB = log.next();
Iterator<DiffEntry> diffs = diffOp.setNewVersion(commit.getId()).setOldVersion(commitB.getId()).setReportTrees(false).call();
while (diffs.hasNext()) {
DiffEntry diff = diffs.next();
if (path.equals(diff.newPath())) {
if (diff.isAdd()) {
String refSpec = commit.getId().toString() + ":" + path;
RevFeature feature = revObjectParse.setRefSpec(refSpec).call(RevFeature.class).get();
report.setFirstVersion(feature, commit);
break;
}
FeatureDiff featureDiff = diffFeature.setNewVersion(Suppliers.ofInstance(diff.getNewObject())).setOldVersion(Suppliers.ofInstance(diff.getOldObject())).call();
Map<PropertyDescriptor, AttributeDiff> attribDiffs = featureDiff.getDiffs();
Iterator<PropertyDescriptor> iter = attribDiffs.keySet().iterator();
while (iter.hasNext()) {
PropertyDescriptor key = iter.next();
Optional<?> value = attribDiffs.get(key).getNewValue();
String attribute = key.getName().toString();
report.addDiff(attribute, value, commit);
}
}
}
commit = commitB;
}
return report;
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class Patch method featureTypeDiffAsString.
private String featureTypeDiffAsString(FeatureTypeDiff diff) {
StringBuilder sb = new StringBuilder();
sb.append(diff.toString() + "\n");
if (!diff.getNewFeatureType().equals(ObjectId.NULL) && !diff.getOldFeatureType().equals(ObjectId.NULL)) {
RevFeatureType oldFeatureType = getFeatureTypeFromId(diff.getOldFeatureType()).get();
RevFeatureType newFeatureType = getFeatureTypeFromId(diff.getNewFeatureType()).get();
ImmutableList<PropertyDescriptor> oldDescriptors = oldFeatureType.sortedDescriptors();
ImmutableList<PropertyDescriptor> newDescriptors = newFeatureType.sortedDescriptors();
BitSet updatedDescriptors = new BitSet(newDescriptors.size());
for (int i = 0; i < oldDescriptors.size(); i++) {
PropertyDescriptor oldDescriptor = oldDescriptors.get(i);
int idx = newDescriptors.indexOf(oldDescriptor);
if (idx != -1) {
updatedDescriptors.set(idx);
} else {
Class<?> oldType = oldDescriptor.getType().getBinding();
sb.append("R\t" + oldDescriptors.get(i).getName().getLocalPart() + "[" + oldType.getName() + "]");
}
}
updatedDescriptors.flip(0, updatedDescriptors.length());
for (int i = updatedDescriptors.nextSetBit(0); i >= 0; i = updatedDescriptors.nextSetBit(i + 1)) {
PropertyDescriptor newDescriptor = newDescriptors.get(i);
Class<?> oldType = newDescriptor.getType().getBinding();
sb.append("A\t" + newDescriptors.get(i).getName().getLocalPart() + "[" + oldType.getName() + "]");
}
}
return sb.toString();
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class PatchSerializer method addElement.
private static void addElement(List<String> lines, Patch patch, Map<String, RevFeatureType> featureTypes) {
String[] headerTokens = lines.get(0).split("\t");
if (headerTokens.length == 4 || headerTokens.length == 3) {
// modified // modification
if (lines.size() == 1) {
// feature type
FeatureTypeDiff diff = new FeatureTypeDiff(headerTokens[0], ObjectId.valueOf(headerTokens[1]), ObjectId.valueOf(headerTokens[2]));
patch.addAlteredTree(diff);
} else {
// feature
String element = Joiner.on("\n").join(lines.subList(1, lines.size()));
ByteArrayInputStream stream;
stream = new ByteArrayInputStream(element.getBytes(Charsets.UTF_8));
String operation = headerTokens[0].trim();
if (operation.equals("M")) {
String fullPath = headerTokens[1].trim();
String oldMetadataId = headerTokens[2].trim();
String newMetadataId = headerTokens[3].trim();
RevFeatureType newRevFeatureType = featureTypes.get(newMetadataId);
RevFeatureType oldRevFeatureType = featureTypes.get(oldMetadataId);
Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
for (int i = 1; i < lines.size(); i++) {
addDifference(lines.get(i), map, oldRevFeatureType, newRevFeatureType);
}
FeatureDiff featureDiff = new FeatureDiff(fullPath, map, oldRevFeatureType, newRevFeatureType);
patch.addModifiedFeature(featureDiff);
} else if (operation.equals("A") || operation.equals("R")) {
String fullPath = headerTokens[1].trim();
String featureTypeId = headerTokens[2].trim();
RevFeatureType revFeatureType;
revFeatureType = featureTypes.get(featureTypeId);
FeatureBuilder featureBuilder = new FeatureBuilder(revFeatureType);
ObjectReader<RevFeature> reader = factory.createFeatureReader();
RevFeature revFeature = reader.read(null, stream);
Feature feature = featureBuilder.build(NodeRef.nodeFromPath(fullPath), revFeature);
if (operation.equals("R")) {
patch.addRemovedFeature(fullPath, feature, revFeatureType);
} else {
patch.addAddedFeature(fullPath, feature, revFeatureType);
}
} else {
throw new IllegalArgumentException("Wrong patch content: " + lines.get(0));
}
}
} else if (headerTokens.length == 1) {
// feature type definition
String element = Joiner.on("\n").join(lines);
ByteArrayInputStream stream = new ByteArrayInputStream(element.getBytes(Charsets.UTF_8));
String[] tokens = lines.get(1).split("\t");
ObjectReader<RevFeatureType> reader = factory.createFeatureTypeReader();
RevFeatureType featureType = reader.read(null, stream);
featureTypes.put(featureType.getId().toString(), featureType);
} else {
throw new IllegalArgumentException("Wrong patch content: " + lines.get(0));
}
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class Show method printFormatted.
public void printFormatted(GeogigCLI cli) throws IOException {
ConsoleReader console = cli.getConsole();
GeoGIG geogig = cli.getGeogig();
for (String ref : refs) {
Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
if (!obj.isPresent()) {
ref = getFullRef(ref);
obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
}
checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
RevObject revObject = obj.get();
if (revObject instanceof RevFeature) {
Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
if (opt.isPresent()) {
RevFeatureType ft = opt.get();
ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
RevFeature feature = (RevFeature) revObject;
Ansi ansi = super.newAnsi(console.getTerminal());
ansi.newline().fg(Color.YELLOW).a("ID: ").reset().a(feature.getId().toString()).newline();
ansi.fg(Color.YELLOW).a("FEATURE TYPE ID: ").reset().a(ft.getId().toString()).newline().newline();
ansi.a("ATTRIBUTES ").newline();
ansi.a("---------- ").newline();
ImmutableList<Optional<Object>> values = feature.getValues();
int i = 0;
for (Optional<Object> value : values) {
ansi.fg(Color.YELLOW).a(attribs.get(i).getName() + ": ").reset();
ansi.a(value.or("[NULL]").toString()).newline();
i++;
}
console.println(ansi.toString());
} else {
CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
console.println(s);
}
} else if (revObject instanceof RevTree) {
RevTree tree = (RevTree) revObject;
Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
checkParameter(opt.isPresent(), "Refspec must resolve to a commit, tree, feature or feature type");
RevFeatureType ft = opt.get();
Ansi ansi = super.newAnsi(console.getTerminal());
ansi.fg(Color.YELLOW).a("TREE ID: ").reset().a(tree.getId().toString()).newline();
ansi.fg(Color.YELLOW).a("SIZE: ").reset().a(Long.toString(tree.size())).newline();
ansi.fg(Color.YELLOW).a("NUMBER Of SUBTREES: ").reset().a(Integer.toString(tree.numTrees()).toString()).newline();
printFeatureType(ansi, ft, true);
console.println(ansi.toString());
} else if (revObject instanceof RevCommit) {
RevCommit commit = (RevCommit) revObject;
Ansi ansi = super.newAnsi(console.getTerminal());
ansi.a(Strings.padEnd("Commit:", 15, ' ')).fg(Color.YELLOW).a(commit.getId().toString()).reset().newline();
ansi.a(Strings.padEnd("Author:", 15, ' ')).fg(Color.GREEN).a(formatPerson(commit.getAuthor())).reset().newline();
ansi.a(Strings.padEnd("Committer:", 15, ' ')).fg(Color.GREEN).a(formatPerson(commit.getAuthor())).reset().newline();
ansi.a(Strings.padEnd("Author date:", 15, ' ')).a("(").fg(Color.RED).a(estimateSince(geogig.getPlatform(), commit.getAuthor().getTimestamp())).reset().a(") ").a(new Date(commit.getAuthor().getTimestamp())).newline();
ansi.a(Strings.padEnd("Committer date:", 15, ' ')).a("(").fg(Color.RED).a(estimateSince(geogig.getPlatform(), commit.getCommitter().getTimestamp())).reset().a(") ").a(new Date(commit.getCommitter().getTimestamp())).newline();
ansi.a(Strings.padEnd("Subject:", 15, ' ')).a(commit.getMessage()).newline();
console.println(ansi.toString());
} else if (revObject instanceof RevFeatureType) {
Ansi ansi = super.newAnsi(console.getTerminal());
printFeatureType(ansi, (RevFeatureType) revObject, false);
console.println(ansi.toString());
} else {
throw new InvalidParameterException("Refspec must resolve to a commit, tree, feature or feature type");
}
console.println();
}
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class Show method printRaw.
private void printRaw(GeogigCLI cli) throws IOException {
ConsoleReader console = cli.getConsole();
GeoGIG geogig = cli.getGeogig();
for (String ref : refs) {
Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
if (!obj.isPresent()) {
ref = getFullRef(ref);
obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
}
checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
RevObject revObject = obj.get();
if (revObject instanceof RevFeature) {
Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
if (opt.isPresent()) {
RevFeatureType ft = opt.get();
ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
RevFeature feature = (RevFeature) revObject;
Ansi ansi = super.newAnsi(console.getTerminal());
ansi.a(ref).newline();
ansi.a(feature.getId().toString()).newline();
ImmutableList<Optional<Object>> values = feature.getValues();
int i = 0;
for (Optional<Object> value : values) {
PropertyDescriptor attrib = attribs.get(i);
ansi.a(attrib.getName()).newline();
PropertyType attrType = attrib.getType();
String typeName = FieldType.forBinding(attrType.getBinding()).name();
if (attrType instanceof GeometryType) {
GeometryType gt = (GeometryType) attrType;
CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
String crsText = CrsTextSerializer.serialize(crs);
ansi.a(typeName).a(" ").a(crsText).newline();
} else {
ansi.a(typeName).newline();
}
ansi.a(value.or("[NULL]").toString()).newline();
i++;
}
console.println(ansi.toString());
} else {
CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
console.println(s);
}
} else {
CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
console.println(s);
}
}
}
Aggregations