private void populateEntry(Context context, Entry entry, Bitstream bitstream) throws DSpaceSwordException { BitstreamFormat format = bitstream.getFormat(); String contentType = null; if (format != null) { contentType = format.getMIMEType(); } SwordUrlManager urlManager = new SwordUrlManager(new SwordConfigurationDSpace(), context); String bsUrl = urlManager.getBitstreamUrl(bitstream); entry.setId(bsUrl); entry.setTitle(bitstream.getName()); String desc = bitstream.getDescription(); if ("".equals(desc) || desc == null) { desc = bitstream.getName(); } entry.setSummary(desc); entry.setUpdated(new Date()); // required, though content is spurious // add an edit-media link for the bitstream ... Abdera abdera = new Abdera(); Link link = abdera.getFactory().newLink(); link.setHref(urlManager.getActionableBitstreamUrl(bitstream)); link.setMimeType(contentType); link.setRel("edit-media"); entry.addLink(link); // set the content of the bitstream entry.setContent(new IRI(bsUrl), contentType); }
private void addAtomManagedDatastream(Feed feed, String contentLocation) throws Exception { String dsId = "DS"; Entry dsEntry = feed.addEntry(); dsEntry.setId(feed.getId().toString() + "/" + dsId); Entry dsvEntry = feed.addEntry(); dsvEntry.setId(dsEntry.getId().toString() + "/" + feed.getUpdatedString()); dsEntry.setTitle(feed.getTitle()); dsEntry.setUpdated(feed.getUpdated()); dsEntry.addLink(dsvEntry.getId().toString(), Link.REL_ALTERNATE); dsEntry.addCategory(MODEL.STATE.uri, "A", null); dsEntry.addCategory(MODEL.CONTROL_GROUP.uri, "M", null); dsEntry.addCategory(MODEL.VERSIONABLE.uri, "true", null); dsvEntry.setTitle(feed.getTitle()); dsvEntry.setUpdated(feed.getUpdated()); ThreadHelper.addInReplyTo(dsvEntry, dsEntry.getId()); dsvEntry.setSummary("summary"); dsvEntry.setContent(new IRI(contentLocation), "text/plain"); }
/* public static Entry ToPackageEntry(PackageItem p, UriInfo uriInfo) { UriBuilder base; if(p.isHistoricalVersion()) { base = uriInfo.getBaseUriBuilder().path("packages").path(p.getName()).path("versions").path(Long.toString(p.getVersionNumber())); } else { base = uriInfo.getBaseUriBuilder().path("packages").path(p.getName()); } //NOTE: Entry extension is not supported in RESTEasy. We need to either use Abdera or get extension //supported in RESTEasy //PackageMetadata metadata = new PackageMetadata(); //metadata.setUuid(p.getUUID()); //metadata.setCreated(p.getCreatedDate().getTime()); //metadata.setLastModified(p.getLastModified().getTime()); //metadata.setLastContributor(p.getLastContributor()); //c.setJAXBObject(metadata); Entry e =new Entry(); e.setTitle(p.getTitle()); e.setSummary(p.getDescription()); e.setPublished(new Date(p.getLastModified().getTimeInMillis())); e.setBase(base.clone().build()); e.setId(base.clone().build()); Iterator<AssetItem> i = p.getAssets(); while (i.hasNext()) { AssetItem item = i.next(); Link link = new Link(); link.setHref((base.clone().path("assets").path(item.getName())).build()); link.setTitle(item.getTitle()); link.setRel("asset"); e.getLinks().add(link); } Content c = new Content(); c.setType(MediaType.APPLICATION_OCTET_STREAM_TYPE); c.setSrc(base.clone().path("binary").build()); e.setContent(c); return e; }*/ public static Entry toAssetEntryAbdera(AssetItem a, UriInfo uriInfo) { URI baseURL; if (a.isHistoricalVersion()) { baseURL = uriInfo .getBaseUriBuilder() .path("packages/{packageName}/assets/{assetName}/versions/{version}") .build(a.getModuleName(), a.getName(), Long.toString(a.getVersionNumber())); } else { baseURL = uriInfo .getBaseUriBuilder() .path("packages/{packageName}/assets/{assetName}") .build(a.getModuleName(), a.getName()); } Factory factory = Abdera.getNewFactory(); org.apache.abdera.model.Entry e = factory.getAbdera().newEntry(); e.setTitle(a.getTitle()); e.setSummary(a.getDescription()); e.setPublished(new Date(a.getLastModified().getTimeInMillis())); e.setBaseUri(baseURL.toString()); e.addAuthor(a.getLastContributor()); e.setId(baseURL.toString()); // generate meta data ExtensibleElement extension = e.addExtension(METADATA); ExtensibleElement childExtension = extension.addExtension(ARCHIVED); // childExtension.setAttributeValue("type", ArtifactsRepository.METADATA_TYPE_STRING); childExtension.addSimpleExtension(VALUE, a.isArchived() ? "true" : "false"); childExtension = extension.addExtension(UUID); childExtension.addSimpleExtension(VALUE, a.getUUID()); childExtension = extension.addExtension(STATE); childExtension.addSimpleExtension(VALUE, a.getState() == null ? "" : a.getState().getName()); childExtension = extension.addExtension(FORMAT); childExtension.addSimpleExtension(VALUE, a.getFormat()); childExtension = extension.addExtension(VERSION_NUMBER); childExtension.addSimpleExtension(VALUE, String.valueOf(a.getVersionNumber())); childExtension = extension.addExtension(CHECKIN_COMMENT); childExtension.addSimpleExtension(VALUE, a.getCheckinComment()); List<CategoryItem> categories = a.getCategories(); childExtension = extension.addExtension(CATEGORIES); for (CategoryItem c : categories) { childExtension.addSimpleExtension(VALUE, c.getName()); } org.apache.abdera.model.Content content = factory.newContent(); content.setSrc(UriBuilder.fromUri(baseURL).path("binary").build().toString()); content.setMimeType("application/octet-stream"); content.setContentType(Type.MEDIA); e.setContentElement(content); return e; }
public static Entry toPackageEntryAbdera(ModuleItem p, UriInfo uriInfo) { URI baseURL; if (p.isHistoricalVersion()) { baseURL = uriInfo .getBaseUriBuilder() .path("packages/{packageName}/versions/{version}") .build(p.getName(), Long.toString(p.getVersionNumber())); } else { baseURL = uriInfo.getBaseUriBuilder().path("packages/{packageName}").build(p.getName()); } Factory factory = Abdera.getNewFactory(); org.apache.abdera.model.Entry e = factory.getAbdera().newEntry(); e.setTitle(p.getTitle()); e.setSummary(p.getDescription()); e.setPublished(new Date(p.getLastModified().getTimeInMillis())); e.setBaseUri(baseURL.toString()); e.addAuthor(p.getLastContributor()); e.setId(baseURL.toString()); Iterator<AssetItem> i = p.getAssets(); while (i.hasNext()) { AssetItem item = i.next(); org.apache.abdera.model.Link l = factory.newLink(); l.setHref( UriBuilder.fromUri(baseURL).path("assets/{assetName}").build(item.getName()).toString()); l.setTitle(item.getTitle()); l.setRel("asset"); e.addLink(l); } // generate meta data ExtensibleElement extension = e.addExtension(METADATA); ExtensibleElement childExtension = extension.addExtension(ARCHIVED); // childExtension.setAttributeValue("type", ArtifactsRepository.METADATA_TYPE_STRING); childExtension.addSimpleExtension(VALUE, p.isArchived() ? "true" : "false"); childExtension = extension.addExtension(UUID); childExtension.addSimpleExtension(VALUE, p.getUUID()); childExtension = extension.addExtension(STATE); childExtension.addSimpleExtension(VALUE, p.getState() == null ? "" : p.getState().getName()); childExtension = extension.addExtension(VERSION_NUMBER); childExtension.addSimpleExtension(VALUE, String.valueOf(p.getVersionNumber())); childExtension = extension.addExtension(CHECKIN_COMMENT); childExtension.addSimpleExtension(VALUE, p.getCheckinComment()); org.apache.abdera.model.Content content = factory.newContent(); content.setSrc(UriBuilder.fromUri(baseURL).path("binary").build().toString()); content.setMimeType("application/octet-stream"); content.setContentType(Type.MEDIA); e.setContentElement(content); return e; }