Skip to content

Commit

Permalink
try to get globalID when OID is not available in serverFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Oct 11, 2024
1 parent 36dd84c commit 9744ef7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- [cygnus-ngsi][arcgis] Fix getObjectId to raise error when ObjectId is not retrieved from entity (#2424)
- [cygnus-ngsi][arcgis] Try to get GlobalID if OID is not found in retrieved feature (#2424)
- [cygnus-ngsi][arcgis] Fix json parse for instance of PolyLine, Polygon and Multipoint (#2423)
- [cygnus-ngsi][arcgis] Check feature table is connected before use it (#2405)
- [cygnus-ngsi][arcgis] Set feature table to not connected after a connection error (#2405)
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class Feature {

private static final String DATE_PATTERN = "MM/dd/yyyy hh:mm:ss";
private static final String OBJECTID_FIELDNAME = "OBJECTID";
private static final String GLOBALID_FIELDNAME = "GLOBALID";

private Geometry geometry;
private Map<String, Object> attributes;
Expand Down Expand Up @@ -277,6 +278,8 @@ public Integer getObjectId() throws ArcgisException {
}
if (objectId.equals(-1)) {
LOGGER.warn("Cant find " + GisAttributeType.OID + " in Feature Object.");
}
if ("".equals(objectId)) {
throw new ArcgisException("Cant find " + GisAttributeType.OID + " in Feature Object.");
} else {
return objectId;
Expand Down Expand Up @@ -310,6 +313,58 @@ public void setObjectId(Integer objectId) throws ArcgisException {
}
}


/**
* Retorna el GLOBALID del GIS de la entidad.
*
* @return GLOBALID value
* @throws ArcgisException
*/
public Integer getGlobalId() throws ArcgisException {
Integer globalId = -1;
for (Map.Entry<String, Object> attribute : attributes.entrySet()) {
if (GLOBALID_FIELDNAME.equalsIgnoreCase(attribute.getKey())) {
globalId = (Integer) attribute.getValue();
break;
}
}
if (globalId.equals(-1)) {
LOGGER.warn("Cant find " + GisAttributeType.GID + " in Feature Object.");
}
if ("".equals(globalId)) {
throw new ArcgisException("Cant find " + GisAttributeType.GID + " in Feature Object.");
} else {
return globalId;
}
}

/**
* Establece el GLOBALID del GIS de la entidad.
*
* @param globalId
* @return
* @throws ArcgisException
*/
public void setGlobalId(Integer globalId) throws ArcgisException {
try {
boolean found = false;

for (Map.Entry<String, Object> attribute : attributes.entrySet()) {
if (GLOBALID_FIELDNAME.equalsIgnoreCase(attribute.getKey())) {
found = true;
attribute.setValue(globalId);
break;
}
}
if (!found) {
attributes.put(GLOBALID_FIELDNAME, globalId);
}
} catch (Exception e) {
throw new ArcgisException(
"Error setting GLOBALID for feature " + this.toString() + " with value " + globalId + " - Error: " + e);
}
}

/**
*
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,17 @@ protected void splitFeatureListIfExists(List<Feature> featureArray,
found = true;
Integer oid = serverFeature.getObjectId();
LOGGER.debug("retrieved ObjectId: " + oid + " from feature " + serverFeatureId);
feature.setObjectId(oid);
if (!oid.equals(-1)) {
feature.setObjectId(oid);
} else {
Integer gid = serverFeature.getGlobalId();
if (!gid.equals(-1)) {
feature.setGlobalId(gid);
} else {
LOGGER.warn("None ObjectId neither GlobalId were found in serverFeature " + serverFeatureId);
feature.setObjectId(oid);
}
}
existentFeatures.add(feature);
}
i++;
Expand Down

0 comments on commit 9744ef7

Please sign in to comment.