Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid W. Miller2015-10-20 16:11:23 +0000
committerDavid W. Miller2015-10-22 16:26:56 +0000
commite56cba6a148e703ec68293fc70761dbb400ae091 (patch)
treedaa02c224ba9d6318ca9bf04e5a6c90e45641993
parente1aa05c0b90c13d59fcaf266bc1de4f2c6b51987 (diff)
downloadorg.eclipse.osee-e56cba6a148e703ec68293fc70761dbb400ae091.tar.gz
org.eclipse.osee-e56cba6a148e703ec68293fc70761dbb400ae091.tar.xz
org.eclipse.osee-e56cba6a148e703ec68293fc70761dbb400ae091.zip
bug[ats_ATS242073]: Fix attribues resource to provide documents
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/AttributeResource.java81
1 files changed, 54 insertions, 27 deletions
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/AttributeResource.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/AttributeResource.java
index ed0a33ab7c4..b24f0bacae4 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/AttributeResource.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/AttributeResource.java
@@ -10,15 +10,17 @@
*******************************************************************************/
package org.eclipse.osee.orcs.rest.internal;
+import java.net.URLEncoder;
import javax.ws.rs.GET;
-import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
-import org.eclipse.osee.framework.core.data.IOseeBranch;
-import org.eclipse.osee.framework.core.data.TokenFactory;
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.data.AttributeReadable;
import org.eclipse.osee.orcs.search.QueryBuilder;
@@ -56,31 +58,56 @@ public class AttributeResource {
}
@GET
- @Produces(MediaType.TEXT_PLAIN)
- public String getAsText() throws OseeCoreException {
- IOseeBranch branch = TokenFactory.createBranch(branchUuid, "");
- QueryFactory factory = OrcsApplication.getOrcsApi().getQueryFactory();
- QueryBuilder queryBuilder = factory.fromBranch(branch).andUuid(artifactUuid);
- if (transactionId > 0) {
- queryBuilder.fromTransaction(transactionId);
- }
- ArtifactReadable exactlyOne = queryBuilder.getResults().getExactlyOne();
+ public Response getResponse() {
+ ResponseBuilder builder = Response.noContent();
+ try {
+ QueryFactory factory = OrcsApplication.getOrcsApi().getQueryFactory();
+ QueryBuilder queryBuilder = factory.fromBranch(branchUuid).andUuid(artifactUuid);
+ if (transactionId > 0) {
+ queryBuilder.fromTransaction(transactionId);
+ }
+ ArtifactReadable exactlyOne = queryBuilder.getResults().getExactlyOne();
- Optional<? extends AttributeReadable<Object>> item =
- Iterables.tryFind(exactlyOne.getAttributes(), new Predicate<AttributeReadable<Object>>() {
- @Override
- public boolean apply(AttributeReadable<Object> attribute) {
- return attribute.getLocalId() == attrId;
- }
- });
+ Optional<? extends AttributeReadable<Object>> item =
+ Iterables.tryFind(exactlyOne.getAttributes(), new Predicate<AttributeReadable<Object>>() {
+ @Override
+ public boolean apply(AttributeReadable<Object> attribute) {
+ return attribute.getLocalId() == attrId;
+ }
+ });
- String toReturn = "";
- if (item.isPresent()) {
- Object value = item.get().getValue();
- if (value != null) {
- toReturn = value.toString();
+ if (item.isPresent()) {
+ Object value = item.get();
+ if (value instanceof AttributeReadable<?>) {
+ builder = Response.ok();
+ AttributeReadable<?> attribute = (AttributeReadable<?>) value;
+ String mediaType = OrcsApplication.getOrcsApi().getOrcsTypes().getAttributeTypes().getMediaType(
+ attribute.getAttributeType());
+ String fileExtension =
+ OrcsApplication.getOrcsApi().getOrcsTypes().getAttributeTypes().getFileTypeExtension(
+ attribute.getAttributeType());
+ if (mediaType.isEmpty() || mediaType.startsWith("text")) {
+ builder.entity(attribute.getDisplayableString());
+ } else {
+ ResultSet<? extends AttributeReadable<Object>> results =
+ exactlyOne.getAttributes(CoreAttributeTypes.Extension);
+ AttributeReadable<Object> extension = results.getOneOrNull();
+ if (extension != null) {
+ fileExtension = extension.getDisplayableString();
+ }
+ Object content = attribute.getValue();
+ builder.entity(content);
+ builder.header("Content-type", mediaType);
+ String filename = URLEncoder.encode(exactlyOne.getName() + "." + fileExtension, "UTF-8");
+ builder.header("Content-Disposition", "attachment; filename=" + filename);
+ }
+ }
+ } else {
+ builder = Response.status(Status.NOT_FOUND);
}
+ } catch (Exception ex) {
+ throw new WebApplicationException(ex);
}
- return toReturn;
+ return builder.build();
}
}

Back to the top