Search in sources :

Example 1 with HealthDataDocumentation

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

the class HealthDataDocumentationServiceTest method getHealthDataDocumentationForId.

@Test
public void getHealthDataDocumentationForId() {
    HealthDataDocumentation doc = makeValidDoc();
    when(mockDao.getDocumentationByIdentifier(TEST_APP_ID, IDENTIFIER)).thenReturn(doc);
    HealthDataDocumentation result = service.getHealthDataDocumentationForId(TEST_APP_ID, IDENTIFIER);
    assertSame(result, doc);
    verify(mockDao).getDocumentationByIdentifier(TEST_APP_ID, IDENTIFIER);
}
Also used : HealthDataDocumentation(org.sagebionetworks.bridge.models.HealthDataDocumentation) Test(org.testng.annotations.Test)

Example 2 with HealthDataDocumentation

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

the class HealthDataDocumentationServiceTest method createOrUpdateHealthDataDocumentation.

@Test
public void createOrUpdateHealthDataDocumentation() {
    RequestContext.set(new RequestContext.Builder().withCallerUserId(TEST_USER_ID).build());
    HealthDataDocumentation doc = makeValidDoc();
    when(mockDao.createOrUpdateDocumentation(doc)).thenReturn(doc);
    HealthDataDocumentation result = service.createOrUpdateHealthDataDocumentation(doc);
    assertSame(result, doc);
    assertEquals(result.getModifiedBy(), TEST_USER_ID);
    assertEquals(result.getModifiedOn(), MOCK_NOW_MILLIS);
    verify(mockDao).createOrUpdateDocumentation(doc);
    RequestContext.set(null);
}
Also used : HealthDataDocumentation(org.sagebionetworks.bridge.models.HealthDataDocumentation) RequestContext(org.sagebionetworks.bridge.RequestContext) Test(org.testng.annotations.Test)

Example 3 with HealthDataDocumentation

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

the class DynamoHealthDataDocumentationDao method getDocumentationForParentId.

/**
 * {@inheritDoc}
 */
@Override
public ForwardCursorPagedResourceList<HealthDataDocumentation> getDocumentationForParentId(@Nonnull String parentId, int pageSize, String offsetKey) {
    // Create hash key.
    DynamoHealthDataDocumentation key = new DynamoHealthDataDocumentation();
    key.setParentId(parentId);
    int pageSizeWithIndicatorRecord = pageSize + 1;
    // Create query.
    DynamoDBQueryExpression<DynamoHealthDataDocumentation> query = new DynamoDBQueryExpression<DynamoHealthDataDocumentation>().withHashKeyValues(key).withLimit(pageSizeWithIndicatorRecord);
    // Add offset key condition to query.
    if (offsetKey != null) {
        Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GE).withAttributeValueList(new AttributeValue().withS(offsetKey));
        query.withRangeKeyCondition("identifier", condition);
    }
    // Query.
    List<DynamoHealthDataDocumentation> dynamoList = queryHelper(query);
    List<HealthDataDocumentation> list = ImmutableList.copyOf(dynamoList);
    list = list.size() <= pageSizeWithIndicatorRecord ? list : list.subList(0, pageSizeWithIndicatorRecord);
    // Calculate nextOffsetKey, if present.
    String nextOffsetKey = null;
    if (list.size() == pageSizeWithIndicatorRecord) {
        nextOffsetKey = Iterables.getLast(list).getIdentifier();
    }
    int limit = Math.min(list.size(), pageSize);
    return new ForwardCursorPagedResourceList<>(list.subList(0, limit), nextOffsetKey);
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HealthDataDocumentation(org.sagebionetworks.bridge.models.HealthDataDocumentation) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)

Example 4 with HealthDataDocumentation

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

the class HealthDataDocumentationValidatorTest method nullDocumentation.

@Test
public void nullDocumentation() {
    HealthDataDocumentation doc = makeValidHealthDataDocumentation();
    doc.setDocumentation(null);
    assertValidatorMessage(HealthDataDocumentationValidator.INSTANCE, doc, "documentation", "cannot be null");
}
Also used : HealthDataDocumentation(org.sagebionetworks.bridge.models.HealthDataDocumentation) Test(org.testng.annotations.Test)

Example 5 with HealthDataDocumentation

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

the class HealthDataDocumentationValidatorTest method emptyTitle.

@Test
public void emptyTitle() {
    HealthDataDocumentation doc = makeValidHealthDataDocumentation();
    doc.setTitle("");
    assertValidatorMessage(HealthDataDocumentationValidator.INSTANCE, doc, "title", "cannot be an empty string");
}
Also used : HealthDataDocumentation(org.sagebionetworks.bridge.models.HealthDataDocumentation) Test(org.testng.annotations.Test)

Aggregations

HealthDataDocumentation (org.sagebionetworks.bridge.models.HealthDataDocumentation)25 Test (org.testng.annotations.Test)20 DynamoDBQueryExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)2 Condition (com.amazonaws.services.dynamodbv2.model.Condition)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 DateTime (org.joda.time.DateTime)1 RequestContext (org.sagebionetworks.bridge.RequestContext)1 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)1 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1