Skip to content

Commit

Permalink
Merge pull request javaswift#62 from roikku/master
Browse files Browse the repository at this point in the history
Added access to the manifest of StoredObjects
  • Loading branch information
roikku committed May 29, 2014
2 parents 1137374 + c263725 commit a6b6b06
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public String getEtag() {
checkForInfoAndAllowHeaderSet();
return info.getEtag();
}

public String getManifest() {
checkForInfoAndAllowHeaderSet();
return info.getManifest() ;
}

public long getContentLength() {
checkForInfoAndAllowHeaderSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected ObjectInformation getReturnObject(HttpResponse response) throws IOExce
info.setContentLength(ObjectContentLength.fromResponse(response));
info.setContentType(ObjectContentType.fromResponse(response));
info.setDeleteAt(DeleteAt.fromResponse(response));
info.setManifest(ObjectManifest.fromResponse(response));
return info;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.javaswift.joss.headers.object;

import org.apache.http.HttpResponse;
import org.javaswift.joss.headers.SimpleHeader;

public class ObjectManifest extends SimpleHeader {
Expand All @@ -23,4 +24,7 @@ public String getObjectPrefix() {
return this.getHeaderValue().substring(this.getHeaderValue().indexOf("/") + 1);
}

public static ObjectManifest fromResponse(HttpResponse response) {
return new ObjectManifest(convertResponseHeader(response, X_OBJECT_MANIFEST));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ObjectInformation extends AbstractInformation {
private ObjectContentType contentType;
private DeleteAfter deleteAfter;
private DeleteAt deleteAt;
private ObjectManifest manifest ;

public Date getLastModifiedAsDate() {
return lastModified == null ? null : lastModified.getDate();
Expand Down Expand Up @@ -78,6 +79,14 @@ public void addHeader(Collection<Header> headers, Header header) {
}
headers.add(header);
}

public String getManifest () {
return (manifest == null) ? (null) : (manifest.getHeaderValue()) ;
}

public void setManifest(ObjectManifest manifest) {
this.manifest = manifest;
}

public Collection<Header> getHeaders() {
Collection<Header> headers = new ArrayList<Header>();
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/javaswift/joss/model/StoredObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ public interface StoredObject extends ObjectStoreEntity, Comparable<DirectoryOrO
* @return etag or hash of the StoredObject
*/
public String getEtag();

/**
* The manifest of the StoredObject (relevant for large objects that are segmented).
* If the Container was read by Container.list, this value will not be refetched from
* the server, unless caching is disabled.
* @return manifest of the StoredObject, or null if the object has no manifest
*/
public String getManifest();

/**
* The number of the bytes used by the StoredObject. If the Container was read by Container.list, this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public ObjectInformation getInfo() {
objectInformation.setEtag(etag);
objectInformation.setLastModified(new ObjectLastModified(lastModified));
objectInformation.setDeleteAt(deleteAt);
objectInformation.setManifest(objectManifest);
return objectInformation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,12 @@ public void uploadSegmentedObjectsThrowsException(@Mocked final UploadInstructio
object.uploadObject(instructions);
}

@Test
public void getManifest() {
Container manifests = account.getContainer("manifests").create();
StoredObject manifest = manifests.getObject("manifest");
manifest.uploadObject(new UploadInstructions(new byte[] {} ).setObjectManifest(new ObjectManifest("segments/segment")));

assertEquals("segments/segment", manifest.getManifest());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.javaswift.joss.headers.object.ObjectContentType.CONTENT_TYPE;
import static org.javaswift.joss.headers.object.ObjectLastModified.LAST_MODIFIED;
import static org.javaswift.joss.headers.object.ObjectMetadata.X_OBJECT_META_PREFIX;
import static org.javaswift.joss.headers.object.ObjectManifest.X_OBJECT_MANIFEST;

public class ObjectInformationCommandImplTest extends BaseCommandTest {

Expand All @@ -37,6 +38,7 @@ private void prepareMetadata() {
prepareHeader(response, CONTENT_LENGTH, "654321", headers);
prepareHeader(response, CONTENT_TYPE, "image/png", headers);
prepareHeader(response, X_DELETE_AT, "1339429105", headers);
prepareHeader(response, X_OBJECT_MANIFEST, "container_segments/object", headers);
prepareHeadersForRetrieval(response, headers);
}

Expand All @@ -58,6 +60,7 @@ public void getInfoSuccess() throws IOException {
assertEquals(654321, info.getContentLength());
assertEquals("image/png", info.getContentType());
assertEquals("1339429105", info.getDeleteAt().getHeaderValue());
assertEquals("container_segments/object", info.getManifest());
}

@Test (expected = NotFoundException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.javaswift.joss.headers.object.DeleteAfter;
import org.javaswift.joss.headers.object.DeleteAt;
import org.javaswift.joss.headers.object.ObjectContentType;
import org.javaswift.joss.headers.object.ObjectManifest;
import org.javaswift.joss.headers.object.ObjectMetadata;
import org.junit.Test;

Expand All @@ -23,6 +24,7 @@ public void joinMetadataAndContentType() {
info.setDeleteAfter(new DeleteAfter(42));
info.setDeleteAt(new DeleteAt(new Date()));
info.setContentType(new ObjectContentType("text/plain"));
info.setManifest(new ObjectManifest("container_segments/object"));
Collection<Header> headers = info.getHeadersIncludingHeader(new ObjectContentType("image/png"));
assertEquals(5, headers.size());
for (Header header : headers) {
Expand All @@ -45,4 +47,10 @@ public void noHeader() {
Collection<Header> headers = info.getHeaders();
assertEquals(0, headers.size());
}

@Test
public void getManifest() {
ObjectInformation info = new ObjectInformation();
assertNull(info.getManifest());
}
}

0 comments on commit a6b6b06

Please sign in to comment.