private List<String> rebuildAttributes(SimpleFeatureType sft) { Layer layer = applicationLayer.getService().getSingleLayer(applicationLayer.getLayerName()); List<String> attributesToRetain = new ArrayList<String>(); for (AttributeDescriptor ad : sft.getAttributes()) { String name = ad.getName(); String fullName = sft.getId() + ":" + name; // if attribute already added return. if (attributesToRetain.contains(fullName)) { return attributesToRetain; } attributesToRetain.add(fullName); // Used for display in JSP if (StringUtils.isNotBlank(ad.getAlias())) { attributeAliases.put(fullName, ad.getAlias()); } if (applicationLayer.getAttribute(sft, name) == null) { ConfiguredAttribute ca = new ConfiguredAttribute(); // default visible if not geometry type // and not a attribute of a related featuretype boolean defaultVisible = true; if (layer.getFeatureType().getId() != sft.getId() || AttributeDescriptor.GEOMETRY_TYPES.contains(ad.getType())) { defaultVisible = false; } ca.setVisible(defaultVisible); ca.setAttributeName(name); ca.setFeatureType(sft); applicationLayer.getAttributes().add(ca); Stripersist.getEntityManager().persist(ca); if (!"save".equals(getContext().getEventName())) { String message = "Nieuw attribuut \"{0}\" gevonden in "; if (layer.getFeatureType().getId() != sft.getId()) { message += "gekoppelde "; } message += "attribuutbron"; if (layer.getFeatureType().getId() == sft.getId()) { message += ": wordt zichtbaar na opslaan"; } getContext().getMessages().add(new SimpleMessage(message, name)); } } } if (sft.getRelations() != null) { for (FeatureTypeRelation rel : sft.getRelations()) { attributesToRetain.addAll(rebuildAttributes(rel.getForeignFeatureType())); } } return attributesToRetain; }
/** * this is fired when a tag start event is found on an xml document * * @param uri namespace for tag being processed * @param localName tag name * @param qName fully qualified name for tag * @param attributes tag attributes * @throws SAXException if parsing fails */ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { // if a class is being parsed if (qName.equalsIgnoreCase(getTagName())) { // set class name from xml attributes mClassName = attributes.getValue(TAG_ATTRIBUTES.name.toString()); // if an attribute is being parsed } else if (qName.equalsIgnoreCase(AttributeDescriptor.TAG_NAME)) { // create an attribute descriptor AttributeDescriptor attribute = new AttributeDescriptor(); // add an attribute to this class mAttributes.add(attribute); // let the attribute parse itself mCtx.pushHandler(attribute); // forward event to new handler attribute.startElement(uri, localName, qName, attributes); } }
private void makeAttributeJSONArray(final SimpleFeatureType layerSft) throws JSONException { List<ConfiguredAttribute> cas = applicationLayer.getAttributes(); // Sort the attributes, by featuretype and the featuretyp Collections.sort( cas, new Comparator<ConfiguredAttribute>() { @Override public int compare(ConfiguredAttribute o1, ConfiguredAttribute o2) { if (o1.getFeatureType() == null) { return -1; } if (o2.getFeatureType() == null) { return 1; } if (o1.getFeatureType().getId().equals(layerSft.getId())) { return -1; } if (o2.getFeatureType().getId().equals(layerSft.getId())) { return 1; } return o1.getFeatureType().getId().compareTo(o2.getFeatureType().getId()); } }); for (ConfiguredAttribute ca : cas) { JSONObject j = ca.toJSONObject(); // Copy alias over from feature type SimpleFeatureType sft = ca.getFeatureType(); if (sft == null) { sft = layerSft; } AttributeDescriptor ad = sft.getAttribute(ca.getAttributeName()); j.put("alias", ad.getAlias()); j.put("featureTypeAttribute", ad.toJSONObject()); attributesJSON.put(j); } }