Search in sources :

Example 1 with TemplateRevisionValidator

use of org.sagebionetworks.bridge.validators.TemplateRevisionValidator 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

DateTime (org.joda.time.DateTime)1 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)1 CreatedOnHolder (org.sagebionetworks.bridge.models.CreatedOnHolder)1 Template (org.sagebionetworks.bridge.models.templates.Template)1 TemplateRevisionValidator (org.sagebionetworks.bridge.validators.TemplateRevisionValidator)1