Search in sources :

Example 1 with CreatedOnHolder

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

the class TemplateRevisionControllerTest method createTemplateRevision.

@Test
public void createTemplateRevision() throws Exception {
    TemplateRevision revision = TemplateRevision.create();
    revision.setMimeType(TEXT);
    revision.setSubject(SUBJECT);
    revision.setDocumentContent(DOCUMENT_CONTENT);
    mockRequestBody(request, revision);
    CreatedOnHolder holder = new CreatedOnHolder(CREATED_ON);
    when(mockRevisionService.createTemplateRevision(eq(TEST_APP_ID), eq(TEMPLATE_GUID), any())).thenReturn(holder);
    controller.createTemplateRevision(TEMPLATE_GUID);
    verify(mockRevisionService).createTemplateRevision(eq(TEST_APP_ID), eq(TEMPLATE_GUID), revisionCaptor.capture());
    TemplateRevision captured = revisionCaptor.getValue();
    assertEquals(captured.getMimeType(), TEXT);
    assertEquals(captured.getSubject(), SUBJECT);
    assertEquals(captured.getDocumentContent(), DOCUMENT_CONTENT);
}
Also used : TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) CreatedOnHolder(org.sagebionetworks.bridge.models.CreatedOnHolder) Test(org.testng.annotations.Test)

Example 2 with CreatedOnHolder

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

the class TemplateRevisionServiceTest method createTemplateRevision.

@Test
public void createTemplateRevision() throws Exception {
    mockGetTemplate();
    TemplateRevision revision = TemplateRevision.create();
    revision.setMimeType(TEXT);
    revision.setSubject(SUBJECT);
    revision.setDocumentContent(DOCUMENT_CONTENT);
    CreatedOnHolder holder = service.createTemplateRevision(TEST_APP_ID, TEMPLATE_GUID, revision);
    assertEquals(holder.getCreatedOn(), CREATED_ON);
    verify(mockTemplateRevisionDao).createTemplateRevision(revisionCaptor.capture());
    TemplateRevision captured = revisionCaptor.getValue();
    assertEquals(captured.getTemplateGuid(), TEMPLATE_GUID);
    assertEquals(captured.getCreatedOn(), CREATED_ON);
    assertEquals(captured.getCreatedBy(), TEST_USER_ID);
    assertEquals(captured.getStoragePath(), STORAGE_PATH);
    assertEquals(captured.getDocumentContent(), DOCUMENT_CONTENT);
    assertEquals(captured.getMimeType(), TEXT);
    assertEquals(captured.getSubject(), SUBJECT);
}
Also used : TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) CreatedOnHolder(org.sagebionetworks.bridge.models.CreatedOnHolder) Test(org.testng.annotations.Test)

Example 3 with CreatedOnHolder

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

the class TemplateRevisionService method createTemplateRevision.

public CreatedOnHolder createTemplateRevision(String appId, String templateGuid, TemplateRevision revision) {
    checkNotNull(appId);
    checkNotNull(templateGuid);
    checkNotNull(revision);
    DateTime createdOn = getDateTime();
    String storagePath = templateGuid + "." + createdOn.getMillis();
    // verify the template GUID is in the user's app.
    Template template = templateDao.getTemplate(appId, templateGuid).orElseThrow(() -> new EntityNotFoundException(Template.class));
    revision.setCreatedOn(createdOn);
    revision.setTemplateGuid(templateGuid);
    revision.setCreatedBy(getUserId());
    revision.setStoragePath(storagePath);
    TemplateRevisionValidator validator = new TemplateRevisionValidator(template.getTemplateType());
    Validate.entityThrowingException(validator, revision);
    templateRevisionDao.createTemplateRevision(revision);
    return new CreatedOnHolder(createdOn);
}
Also used : EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) TemplateRevisionValidator(org.sagebionetworks.bridge.validators.TemplateRevisionValidator) DateTime(org.joda.time.DateTime) CreatedOnHolder(org.sagebionetworks.bridge.models.CreatedOnHolder) Template(org.sagebionetworks.bridge.models.templates.Template)

Aggregations

CreatedOnHolder (org.sagebionetworks.bridge.models.CreatedOnHolder)3 TemplateRevision (org.sagebionetworks.bridge.models.templates.TemplateRevision)2 Test (org.testng.annotations.Test)2 DateTime (org.joda.time.DateTime)1 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)1 Template (org.sagebionetworks.bridge.models.templates.Template)1 TemplateRevisionValidator (org.sagebionetworks.bridge.validators.TemplateRevisionValidator)1