@Override public String getGeometryAttributeName() throws LayerException { return fixName(getFeatureInfo().getGeometryType().getName()); }
private AbstractReadOnlyAttributeInfo getAttributeByName(String name) { if (name != null) { for (AbstractAttributeInfo attributeInfo : layer.getLayerInfo().getFeatureInfo().getAttributes()) { if (attributeInfo instanceof AbstractReadOnlyAttributeInfo && attributeInfo.getName().equals(name)) { return (AbstractReadOnlyAttributeInfo) attributeInfo; } } } return null; }
@Override public List<Attribute<?>> getAttributes(String attributeName, Filter filter) throws LayerException { if (attributeName == null) { throw new HibernateLayerException(ExceptionCode.ATTRIBUTE_UNKNOWN, (Object) null); } AssociationAttributeInfo attributeInfo = getRecursiveAttributeInfo(attributeName, getFeatureInfo() .getAttributes()); Session session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(attributeInfo.getFeature().getDataSourceName()); CriteriaVisitor visitor = new CriteriaVisitor((HibernateFeatureModel) getFeatureModel(), dateFormat); if (filter != null) { Criterion c = (Criterion) filter.accept(visitor, null); if (c != null) { criteria.add(c); } } List<Attribute<?>> attributes = new ArrayList<Attribute<?>>(); for (Object object : criteria.list()) { try { attributes.add(converterService.toDto(object, attributeInfo)); } catch (GeomajasException e) { throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_ATTRIBUTE_TYPE_PROBLEM, attributeName); } } return attributes; }
try { Session session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(getFeatureInfo().getDataSourceName()); if (filter != null) { if (filter != Filter.INCLUDE) { if (getFeatureInfo().getSortAttributeName() != null) { if (SortType.ASC.equals(getFeatureInfo().getSortType())) { criteria.addOrder(Order.asc(getFeatureInfo().getSortAttributeName())); } else { criteria.addOrder(Order.desc(getFeatureInfo().getSortAttributeName())); .getDataSourceName(), filter.toString());
FeatureInfo fi = new FeatureInfo(); PrimitiveAttributeInfo identifier = null; for (AttributeDescriptor ad : sft.getAttributeDescriptors()) { && !ad.getLocalName().contains("/")) { // ignore attributes with slash in name PrimitiveAttributeInfo pai = toPrimitiveAttributeInfo(ad); fi.getAttributes().add(pai); if (ad.getType().isIdentified() && identifier == null) { identifier = pai; identifier = (PrimitiveAttributeInfo) fi.getAttributes().get(0); fi.setDataSourceName(layerName); fi.setGeometryType(toGeometryAttributeInfo(sft.getGeometryDescriptor())); fi.setIdentifier(identifier);
public void setData(DynamicVectorLayerConfiguration layerConfig) { this.layerConfig = layerConfig; FeatureInfo fi = layerConfig.getClientVectorLayerInfo().getFeatureInfo(); String labelFieldName = layerConfig.getClientVectorLayerInfo().getNamedStyleInfo().getLabelStyle() .getLabelAttributeName(); PrimitiveAttributeInfo idField = fi.getIdentifier(); for (AttributeInfo ai : fi.getAttributes()) { if (ai instanceof PrimitiveAttributeInfo) { ListGridRecord lgr = new ListGridRecord(); PrimitiveAttributeInfo pai = (PrimitiveAttributeInfo) ai; lgr.setAttribute(FLD_NAME, pai.getName()); lgr.setAttribute(FLD_TYPE, pai.getType().toString()); lgr.setAttribute(FLD_IDENTIFYING, pai.isIdentifying()); lgr.setAttribute(FLD_IDFIELD, (pai.equals(idField))); lgr.setAttribute(FLD_LABELFIELD, pai.getName().equals(labelFieldName)); lgr.setAttribute(FLD_LABEL, pai.getLabel()); lgr.setAttribute(FLD_OBJECT, pai); grid.addData(lgr); if (pai.getName().equals(labelFieldName)) { currentLabelField = lgr; } if (pai.equals(idField)) { currentIdField = lgr; } if (!pai.isHidden()) { grid.selectRecord(lgr); } } // else unsupported } }
private Object getFeature(String featureId) throws HibernateLayerException { Session session = getSessionFactory().getCurrentSession(); return session.get(getFeatureInfo().getDataSourceName(), (Serializable) ConvertUtils.convert(featureId, getEntityMetadata().getIdentifierType().getReturnedClass())); }
private SearchCriterion[] buildCriteria() { List<SearchCriterion> critters = new ArrayList<SearchCriterion>(); String idField = layer.getLayerInfo().getFeatureInfo().getIdentifier().getName(); if (features != null) { for (Feature feat : features) { critters.add(new SearchCriterion(idField, "=", feat.getId())); } } return critters.toArray(new SearchCriterion[critters.size()]); } }
public DynamicVectorLayerConfiguration getData() { if (currentIdField == null || currentLabelField == null) { return null; } FeatureInfo fi = layerConfig.getClientVectorLayerInfo().getFeatureInfo(); fi.setIdentifier((PrimitiveAttributeInfo) currentIdField.getAttributeAsObject(FLD_OBJECT)); layerConfig.getClientVectorLayerInfo().getNamedStyleInfo().getLabelStyle() .setLabelAttributeName(currentLabelField.getAttributeAsString(FLD_NAME)); for (ListGridRecord r : grid.getRecords()) { PrimitiveAttributeInfo pai = (PrimitiveAttributeInfo) r.getAttributeAsObject(FLD_OBJECT); pai.setLabel(r.getAttributeAsString(FLD_LABEL)); pai.setIdentifying(r.getAttributeAsBoolean(FLD_IDENTIFYING)); pai.setHidden(!grid.isSelected(r)); pai.setType(PrimitiveType.fromValue(r.getAttributeAsString(FLD_TYPE))); } return layerConfig; }
@SuppressWarnings("deprecation") // see GBE-321 private List<PrimitiveAttributeInfo> getPrimitiveAttributeInfo(VectorLayer layer) { List<PrimitiveAttributeInfo> res = new ArrayList<PrimitiveAttributeInfo>(); Collection<AbstractAttributeInfo> ais = layer.getLayerInfo().getFeatureInfo().getAttributesMap().values(); for (AbstractAttributeInfo ai : ais) { if (ai instanceof PrimitiveAttributeInfo && !((PrimitiveAttributeInfo) ai).isHidden()) { res.add((PrimitiveAttributeInfo) ai); } } return res; }
FeatureInfo fi = new FeatureInfo(); PrimitiveAttributeInfo identifier = null; for (AttributeDescriptor ad : sft.getAttributeDescriptors()) { && !ad.getLocalName().contains("/")) { // ignore attributes with slash in name PrimitiveAttributeInfo pai = toPrimitiveAttributeInfo(ad); fi.getAttributes().add(pai); if (ad.getType().isIdentified() && identifier == null) { identifier = pai; identifier = (PrimitiveAttributeInfo) fi.getAttributes().get(0); fi.setDataSourceName(layerName); fi.setGeometryType(toGeometryAttributeInfo(sft.getGeometryDescriptor())); fi.setIdentifier(identifier);
@Override public Object newInstance() throws LayerException { try { return getEntityMetadata().instantiate(null, (SessionImplementor) getSessionFactory().getCurrentSession()); } catch (Exception e) { // NOSONAR throw new LayerException(e, ExceptionCode.HIBERNATE_CANNOT_CREATE_POJO, getFeatureInfo() .getDataSourceName()); } }
@Override public String getId(Object feature) throws LayerException { Entity entity = entityMapper.asEntity(feature); Object id = entity.getId(getFeatureInfo().getIdentifier().getName()); return id == null ? null : id.toString(); }
@SuppressWarnings("deprecation") // see GBE-321 private List<PrimitiveAttributeInfo> getPrimitiveAttributeInfo(VectorLayer layer) { List<PrimitiveAttributeInfo> res = new ArrayList<PrimitiveAttributeInfo>(); Collection<AbstractAttributeInfo> ais = layer.getLayerInfo().getFeatureInfo().getAttributesMap().values(); for (AbstractAttributeInfo ai : ais) { if (ai instanceof PrimitiveAttributeInfo && !((PrimitiveAttributeInfo) ai).isHidden()) { res.add((PrimitiveAttributeInfo) ai); } } return res; }
private static Map<String, String> geometryCriterionToFilters(GeometryCriterion criterion, MapModel mapModel) { Map<String, String> filters = new LinkedHashMap<String, String>(); org.geomajas.gwt.client.spatial.geometry.Geometry mapGeom = GeometryConverter.toGwt(criterion.getGeometry()); String wktGeom = mapGeom.toWkt(); String method; switch (criterion.getOperator()) { case SearchByLocationRequest.QUERY_INTERSECTS: method = "INTERSECTS"; break; case SearchByLocationRequest.QUERY_CONTAINS: method = "CONTAINS"; break; case SearchByLocationRequest.QUERY_TOUCHES: method = "TOUCHES"; break; case SearchByLocationRequest.QUERY_WITHIN: method = "WITHIN"; break; default: return null; } for (String serverLayerId : criterion.getServerLayerIds()) { VectorLayer vl = findVectorLayer(mapModel, serverLayerId); if (vl != null) { String geomAttName = vl.getLayerInfo().getFeatureInfo().getGeometryType().getName(); filters.put(serverLayerId, method + "(" + geomAttName + ", " + wktGeom + ")"); } } return filters; }
private AssociationAttributeInfo getRecursiveAttributeInfo(String name, List<AttributeInfo> infos) { for (AttributeInfo attributeInfo : infos) { if (attributeInfo instanceof AssociationAttributeInfo) { AssociationAttributeInfo associationAttributeInfo = (AssociationAttributeInfo) attributeInfo; if (name.equals(attributeInfo.getName())) { return associationAttributeInfo; } else if (name.startsWith(attributeInfo.getName())) { String childName = name.substring(attributeInfo.getName().length() + 1); return getRecursiveAttributeInfo(childName, associationAttributeInfo.getFeature().getAttributes()); } } } return null; }
/** * Set session factory. * * @param sessionFactory session factory * @throws HibernateLayerException could not get class metadata for data source */ public void setSessionFactory(SessionFactory sessionFactory) throws HibernateLayerException { try { this.sessionFactory = sessionFactory; if (null != layerInfo) { entityMetadata = sessionFactory.getClassMetadata(layerInfo.getFeatureInfo().getDataSourceName()); } } catch (Exception e) { // NOSONAR throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_NO_SESSION_FACTORY); } } }
if (properties[0].equals(getFeatureInfo().getIdentifier().getName())) { tempFeature = getId(feature); } else {
@SuppressWarnings({"rawtypes", "deprecation" }) // see GBE-321 public void toShapeFile(File shapeFile, VectorLayer layer, List<InternalFeature> features) throws Exception { if (features.size() == 0) { return; } List<PrimitiveAttributeInfo> attInfos = getPrimitiveAttributeInfo(layer); SimpleFeatureType type = createFeatureType(layer.getId(), layer.getLayerInfo().getFeatureInfo() .getGeometryType().getName(), features.get(0).getGeometry().getGeometryType(), features.get(0) .getGeometry().getSRID(), attInfos); DefaultFeatureCollection collection = new DefaultFeatureCollection(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type); for (InternalFeature feature : features) { featureBuilder.add(feature.getGeometry()); Map<String, Attribute> atts = feature.getAttributes(); for (PrimitiveAttributeInfo pai : attInfos) { featureBuilder.add(atts.get(pai.getName()).getValue()); } SimpleFeature sf = featureBuilder.buildFeature(feature.getId()); collection.add(sf); } buildShapeFile(shapeFile, layer, collection, type); }
private boolean isIdentifying(String key, Layer layer) { if (layer instanceof VectorLayer) { ClientVectorLayerInfo c = (ClientVectorLayerInfo) layer.getLayerInfo(); for (AbstractAttributeInfo a : c.getFeatureInfo().getAttributes()) { if (a.getName().equalsIgnoreCase(key)) { return a instanceof AbstractReadOnlyAttributeInfo && ((AbstractReadOnlyAttributeInfo) a).isIdentifying(); } } } return false; }