Search in sources :

Example 16 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class AppControllerTest method updateApp.

@Test
public void updateApp() throws Exception {
    when(mockSession.getAppId()).thenReturn(TEST_APP_ID);
    doReturn(mockSession).when(controller).getAuthenticatedSession(SUPERADMIN);
    App created = App.create();
    created.setVersion(3L);
    when(mockAppService.updateApp(any(), anyBoolean())).thenReturn(created);
    App app = App.create();
    app.setName("value to seek");
    mockRequestBody(mockRequest, app);
    VersionHolder holder = controller.updateApp(TEST_APP_ID);
    assertEquals(holder.getVersion(), Long.valueOf(3L));
    verify(mockAppService).updateApp(appCaptor.capture(), eq(true));
    assertEquals(appCaptor.getValue().getName(), "value to seek");
}
Also used : TestUtils.getValidApp(org.sagebionetworks.bridge.TestUtils.getValidApp) DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) App(org.sagebionetworks.bridge.models.apps.App) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) Test(org.testng.annotations.Test)

Example 17 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class AppConfigElementServiceTest method createElement.

@Test
public void createElement() {
    AppConfigElement element = TestUtils.getAppConfigElement();
    element.setRevision(null);
    element.setDeleted(true);
    when(dao.saveElementRevision(element)).thenReturn(VERSION_HOLDER);
    VersionHolder returned = service.createElement(TEST_APP_ID, element);
    assertEquals(returned, VERSION_HOLDER);
    verify(dao).saveElementRevision(elementCaptor.capture());
    // These have been correctly reset
    assertEquals(elementCaptor.getValue().getRevision(), new Long(1));
    AppConfigElement captured = elementCaptor.getValue();
    assertNull(captured.getVersion());
    assertFalse(captured.isDeleted());
    assertEquals(captured.getAppId(), TEST_APP_ID);
    assertEquals(captured.getKey(), TEST_APP_ID + ":id");
    assertEquals(captured.getCreatedOn(), TIMESTAMP.getMillis());
    assertEquals(captured.getModifiedOn(), TIMESTAMP.getMillis());
}
Also used : AppConfigElement(org.sagebionetworks.bridge.models.appconfig.AppConfigElement) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) Test(org.testng.annotations.Test)

Example 18 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class AppConfigElementServiceTest method updateElementRevision.

@Test
public void updateElementRevision() {
    AppConfigElement element = TestUtils.getAppConfigElement();
    AppConfigElement existing = TestUtils.getAppConfigElement();
    when(dao.getElementRevision(TEST_APP_ID, element.getId(), element.getRevision())).thenReturn(existing);
    when(dao.saveElementRevision(element)).thenReturn(VERSION_HOLDER);
    VersionHolder returned = service.updateElementRevision(TEST_APP_ID, element);
    assertEquals(returned, VERSION_HOLDER);
    verify(dao).saveElementRevision(elementCaptor.capture());
    AppConfigElement captured = elementCaptor.getValue();
    assertEquals(captured.getAppId(), TEST_APP_ID);
    assertEquals(captured.getKey(), TEST_APP_ID + ":id");
    assertNotEquals(captured.getCreatedOn(), TIMESTAMP.getMillis());
    assertEquals(captured.getModifiedOn(), TIMESTAMP.getMillis());
}
Also used : AppConfigElement(org.sagebionetworks.bridge.models.appconfig.AppConfigElement) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) Test(org.testng.annotations.Test)

Example 19 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class AppConfigElementsController method createElement.

@PostMapping("/v3/appconfigs/elements")
@ResponseStatus(HttpStatus.CREATED)
public VersionHolder createElement() {
    UserSession session = getAuthenticatedSession(DEVELOPER);
    AppConfigElement element = parseJson(AppConfigElement.class);
    VersionHolder version = service.createElement(session.getAppId(), element);
    // App config elements are included in the app configs, so allow cache to update
    cacheProvider.removeSetOfCacheKeys(CacheKey.appConfigList(session.getAppId()));
    return version;
}
Also used : AppConfigElement(org.sagebionetworks.bridge.models.appconfig.AppConfigElement) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 20 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class AppConfigElementsController method updateElementRevision.

@PostMapping("/v3/appconfigs/elements/{id}/revisions/{revision}")
public VersionHolder updateElementRevision(@PathVariable String id, @PathVariable String revision) {
    UserSession session = getAuthenticatedSession(DEVELOPER);
    Long revisionLong = BridgeUtils.getLongOrDefault(revision, null);
    if (revisionLong == null) {
        throw new BadRequestException("Revision is not a valid revision number");
    }
    AppConfigElement element = parseJson(AppConfigElement.class);
    element.setId(id);
    element.setRevision(revisionLong);
    VersionHolder holder = service.updateElementRevision(session.getAppId(), element);
    // App config elements are included in the app configs, so allow cache to update
    cacheProvider.removeSetOfCacheKeys(CacheKey.appConfigList(session.getAppId()));
    return holder;
}
Also used : AppConfigElement(org.sagebionetworks.bridge.models.appconfig.AppConfigElement) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

VersionHolder (org.sagebionetworks.bridge.models.VersionHolder)25 Test (org.testng.annotations.Test)17 App (org.sagebionetworks.bridge.models.apps.App)9 AppConfigElement (org.sagebionetworks.bridge.models.appconfig.AppConfigElement)8 Study (org.sagebionetworks.bridge.models.studies.Study)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 TestUtils.getValidApp (org.sagebionetworks.bridge.TestUtils.getValidApp)5 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)5 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)3 AppAndUsers (org.sagebionetworks.bridge.models.apps.AppAndUsers)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 DateTime (org.joda.time.DateTime)2 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)2 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)2 StudyValidator (org.sagebionetworks.bridge.validators.StudyValidator)2 RequestContext (org.sagebionetworks.bridge.RequestContext)1 CacheKey (org.sagebionetworks.bridge.cache.CacheKey)1 EntityAlreadyExistsException (org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException)1 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)1 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)1