diff --git a/api/src/main/java/org/openmrs/module/attachments/AttachmentsConstants.java b/api/src/main/java/org/openmrs/module/attachments/AttachmentsConstants.java index c9af5b2..50449b8 100644 --- a/api/src/main/java/org/openmrs/module/attachments/AttachmentsConstants.java +++ b/api/src/main/java/org/openmrs/module/attachments/AttachmentsConstants.java @@ -139,5 +139,6 @@ public static enum ContentFamily { * PRIVILEGES */ public static final String CREATE_ATTACHMENTS = "Create Attachments"; + public static final String VIEW_ATTACHMENTS = "View Attachments"; } diff --git a/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java b/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java index 67d069e..3097b3f 100644 --- a/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java +++ b/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java @@ -12,6 +12,12 @@ import java.util.Arrays; import java.util.List; +import io.swagger.models.Model; +import io.swagger.models.ModelImpl; +import io.swagger.models.properties.ByteArrayProperty; +import io.swagger.models.properties.DateProperty; +import io.swagger.models.properties.RefProperty; +import io.swagger.models.properties.StringProperty; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.BooleanUtils; @@ -30,6 +36,7 @@ import org.openmrs.module.attachments.ComplexObsSaver; import org.openmrs.module.attachments.obs.Attachment; import org.openmrs.module.attachments.obs.ValueComplex; +import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.ConversionUtil; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -178,9 +185,28 @@ public Object upload(MultipartFile file, RequestContext context) throws Response public DelegatingResourceDescription getCreatableProperties() { DelegatingResourceDescription description = new DelegatingResourceDescription(); description.addProperty("comment"); + description.addProperty("dateTime"); + description.addProperty("filename"); + description.addProperty("bytesMimeType"); + description.addProperty("bytesContentFamily"); + description.addProperty("complexData"); return description; } + @Override + public Model getCREATEModel(Representation rep) { + return new ModelImpl().property("comment", new StringProperty()).property("dateTime", new DateProperty()) + .property("filename", new StringProperty()).property("bytesMimeType", new StringProperty()) + + .property("bytesContentFamily", new EnumProperty(AttachmentsConstants.ContentFamily.class)) + .property("complexData", new StringProperty(StringProperty.Format.URI)); + } + + @Override + public Model getUPDATEModel(Representation rep) { + return getCREATEModel(rep); + } + @Override public DelegatingResourceDescription getRepresentationDescription(Representation rep) { DelegatingResourceDescription description = new DelegatingResourceDescription(); @@ -194,6 +220,15 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return description; } + @Override + public Model getGETModel(Representation rep) { + ModelImpl model = (ModelImpl) super.getGETModel(rep); + return model.property("uuid", new StringProperty()).property("dateTime", new DateProperty()) + .property("filename", new StringProperty()).property("comment", new StringProperty()) + .property("bytesMimeType", new StringProperty()) + .property("bytesContentFamily", new EnumProperty(AttachmentsConstants.ContentFamily.class)); + } + /** * Voids the encounter if it contains no non-voided obs. *