Skip to content

Commit

Permalink
Merge pull request #2425 from telefonicaid/fix/check_object_id_not_fo…
Browse files Browse the repository at this point in the history
…und_by_get_object

Try to get GlobalID if OID is not found in retrieved feature (arcgis)
  • Loading branch information
fgalan authored Oct 11, 2024
2 parents 2347642 + 9296c15 commit 5f534da
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [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 @@ -275,7 +276,9 @@ public Integer getObjectId() throws ArcgisException {
break;
}
}

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 {
Expand Down Expand Up @@ -306,7 +309,59 @@ public void setObjectId(Integer objectId) throws ArcgisException {
}
} catch (Exception e) {
throw new ArcgisException(
"Error setting OBJECTID for feature " + this.toString() + " - Error: " + e);
"Error setting OBJECTID for feature " + this.toString() + " with value " + objectId + " - Error: " + e);
}
}


/**
* 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,19 @@ protected void splitFeatureListIfExists(List<Feature> featureArray,
if (featureId.equalsIgnoreCase(serverFeatureId)) {
found = true;
Integer oid = serverFeature.getObjectId();
feature.setObjectId(oid);
LOGGER.debug("retrieved ObjectId: " + oid + " from feature " + serverFeatureId);
if (!oid.equals(-1)) {
feature.setObjectId(oid);
} else {
Integer gid = serverFeature.getGlobalId();
if (!gid.equals(-1)) {
LOGGER.info(" GlobalId " + gid + " found in serverFeature " + serverFeatureId);
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 5f534da

Please sign in to comment.