Source:
public Response getResponse() { ResponseBuilder builder = Response.noContent(); try { 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(); Optional<? extends AttributeReadable<Object>> item = Iterables.tryFind(exactlyOne.getAttributes(), new Predicate<AttributeReadable<Object>>() { @Override public boolean apply(AttributeReadable<Object> attribute) { return attribute.getLocalId() == attrId; } }); if (item.isPresent()) { Object value = item.get(); if (value != null) { 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); } } } } } catch (Exception ex) { throw new WebApplicationException(ex); } return builder.build(); }

Target:
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; } }); 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 builder.build(); }