Skip to content

Commit

Permalink
Fixed FoI generation failing when user can't create FoIs
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Sep 11, 2023
1 parent 2c4cd97 commit cbcc0bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.geojson.Point;
import org.json.JSONException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer;
Expand Down Expand Up @@ -569,6 +570,29 @@ void test_08d_ObservationsFromDatastreamRead() throws ServiceFailureException, U
fetchForCode(OBS_CREATE_P2, serviceObsCreaterProject2, link, 404);
}

@Test
void test_08e_ObservationCreate() {
LOGGER.info(" test_08e_ObservationCreate");
EntityCreator creator = (user) -> mdlSensing.newObservation(user + " Observation", DATASTREAMS.get(0));

createForFail(OBS_CREATE_P2, serviceObsCreaterProject2, creator, serviceAdmin.dao(mdlSensing.etObservation), OBSERVATIONS, H403);
createForOk(OBS_CREATE_P1, serviceObsCreaterProject1, creator, serviceAdmin.dao(mdlSensing.etObservation), OBSERVATIONS);
}

@Test
void test_08f_ObservationCreateNewFoi() throws ServiceFailureException {
LOGGER.info(" test_08f_ObservationCreateNewFoi");
// Create a new Location for Thing 1, so a new FoI must be generated.
Entity newLocation = mdlSensing.newLocation("testFoiGeneration", "Testing if FoI generation works", new Point(10.0, 49.0))
.addNavigationEntity(mdlSensing.npLocationThings, THINGS.get(0));
serviceAdmin.create(newLocation);

EntityCreator creator = (user) -> mdlSensing.newObservation(user + " Observation", DATASTREAMS.get(0));

createForFail(OBS_CREATE_P2, serviceObsCreaterProject2, creator, serviceAdmin.dao(mdlSensing.etObservation), OBSERVATIONS, H403);
createForOk(OBS_CREATE_P1, serviceObsCreaterProject1, creator, serviceAdmin.dao(mdlSensing.etObservation), OBSERVATIONS);
}

@Test
void test_09_ObservedPropertyCreate() {
LOGGER.info(" test_09_ObservedPropertyCreate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,14 @@ public Entity generateFeatureOfInterest(JooqPersistenceManager pm, ResultQuery<R
.setProperty(ModelRegistry.EP_ENCODINGTYPE, encoding)
.setProperty(pluginCoreModel.epFeature, locObject)
.setProperty(ModelRegistry.EP_PROPERTIES, properties.getMapValue());

// Switch to ADMIN user
PrincipalExtended userPrincipal = PrincipalExtended.getLocalPrincipal();
PrincipalExtended.setLocalPrincipal(PrincipalExtended.INTERNAL_ADMIN_PRINCIPAL);
pm.insert(foi, UpdateMode.INSERT_STA_11);
// Switch back to normal user
PrincipalExtended.setLocalPrincipal(userPrincipal);

Object foiId = foi.getId().getValue();
dslContext.update(ql)
.set(((TableField) ql.getGenFoiId()), foi.getId().getValue())
Expand Down

0 comments on commit cbcc0bc

Please sign in to comment.