Skip to content

Commit aa530c8

Browse files
andreapetrucci93lap82
authored andcommitted
[D4CRIS-506] improved CottageLabs implementation to reflect change request by new-generation OpenAIRE repository
1 parent da6f2a9 commit aa530c8

13 files changed

+185
-11
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.openarchives</groupId>
88
<artifactId>resourcesync</artifactId>
9-
<version>0.9-SNAPSHOT</version>
9+
<version>1.1-SNAPSHOT</version>
1010

1111
<build>
1212
<plugins>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.openarchives.resourcesync;
2+
3+
import java.util.Date;
4+
5+
public class ChangeDump extends UrlSet
6+
{
7+
8+
public ChangeDump(Date from, String resourceSync)
9+
{
10+
super(ResourceSync.CAPABILITY_CHANGEDUMP);
11+
this.setFrom(from);
12+
if (resourceSync != null)
13+
{
14+
this.addLn(ResourceSync.CAPABILITY_RESOURCESYNC, resourceSync);
15+
}
16+
}
17+
18+
public ChangeDump()
19+
{
20+
this(new Date(), null);
21+
}
22+
23+
public void addResourceZip(URL zip)
24+
{
25+
this.addUrl(zip);
26+
}
27+
28+
public URL addResourceZip(String zipUrl, Date lastMod, String type, long length)
29+
{
30+
URL url = new URL();
31+
url.setLoc(zipUrl);
32+
url.setLastModified(lastMod);
33+
url.setType(type);
34+
url.setLength(length);
35+
this.addResourceZip(url);
36+
return url;
37+
}
38+
}

src/main/java/org/openarchives/resourcesync/ChangeList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
public class ChangeList extends UrlSet
66
{
7+
8+
79
public ChangeList()
810
{
911
this(null, null, null, null);
@@ -31,7 +33,7 @@ public ChangeList(Date from, Date until, String capabilityList, String changeLis
3133

3234
if (capabilityList != null)
3335
{
34-
this.addLn(ResourceSync.REL_RESOURCESYNC, capabilityList);
36+
this.addLn(ResourceSync.REL_UP, capabilityList);
3537
}
3638
}
3739

src/main/java/org/openarchives/resourcesync/ChangeListArchive.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ChangeListArchive(Date from, Date until, String capabilityList)
4444

4545
if (capabilityList != null)
4646
{
47-
this.addLn(ResourceSync.REL_RESOURCESYNC, capabilityList);
47+
this.addLn(ResourceSync.REL_UP, capabilityList);
4848
}
4949
}
5050

src/main/java/org/openarchives/resourcesync/ResourceDump.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public ResourceDump(Date from, String resourceSync)
1313
this.setFrom(from);
1414
if (resourceSync != null)
1515
{
16-
this.addLn(ResourceSync.CAPABILITY_RESOURCESYNC, resourceSync);
16+
this.addLn(ResourceSync.REL_UP, resourceSync);
1717
}
1818
}
1919

@@ -37,4 +37,13 @@ public URL addResourceZip(String zipUrl, Date lastMod, String type, long length)
3737
this.addResourceZip(url);
3838
return url;
3939
}
40+
public URL addResourceZip(String zipUrl, Date lastMod, String type)
41+
{
42+
URL url = new URL();
43+
url.setLoc(zipUrl);
44+
url.setLastModified(lastMod);
45+
url.setType(type);
46+
this.addResourceZip(url);
47+
return url;
48+
}
4049
}

src/main/java/org/openarchives/resourcesync/ResourceList.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,27 @@ public ResourceList(Date lastMod, String capabilityList, boolean dump)
5454

5555
if (capabilityList != null)
5656
{
57-
this.addLn(ResourceSync.REL_RESOURCESYNC, capabilityList);
57+
this.addLn(ResourceSync.REL_UP, capabilityList);
5858
}
5959
}
60+
public ResourceList(Date lastMod, String capabilityList, boolean dump,boolean changeDump)
61+
{
62+
super(changeDump ? ResourceSync.CAPABILITY_CHANGEDUMP_MANIFEST : ResourceSync.CAPABILITY_RESOURCELIST);
63+
64+
if (lastMod == null)
65+
{
66+
this.setFrom(new Date());
67+
}
68+
else
69+
{
70+
this.setFrom(lastMod);
71+
}
6072

73+
if (capabilityList != null)
74+
{
75+
this.addLn(ResourceSync.REL_UP, capabilityList);
76+
}
77+
}
6178
public void addResource(URL resource)
6279
{
6380
this.addEntry(resource);

src/main/java/org/openarchives/resourcesync/ResourceSync.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public class ResourceSync
3030
public static String REL_PROFILE = "profile";
3131

3232
// capabilities
33-
public static String CAPABILITY_RESOURCESYNC = "resourcesync";
33+
public static String CAPABILITY_RESOURCESYNC = "description";
3434
public static String CAPABILITY_RESOURCELIST = "resourcelist";
3535
public static String CAPABILITY_RESOURCELIST_ARCHIVE = "resourcelist-archive";
3636
public static String CAPABILITY_CHANGELIST = "changelist";
37-
public static String CAPABILITY_CHANGELIST_ARCHIVE = "changelist-archive";
37+
public static String CAPABILITY_CHANGELIST_ARCHIVE = "changelistindex";
3838
public static String CAPABILITY_RESOURCEDUMP = "resourcedump";
3939
public static String CAPABILITY_RESOURCEDUMP_ARCHIVE = "resourcedump-archive";
4040
public static String CAPABILITY_CHANGEDUMP = "changedump";

src/main/java/org/openarchives/resourcesync/ResourceSyncDescription.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,29 @@ public List<ResourceSyncEntry> getCapabilityLists()
4747
{
4848
return this.getUrls();
4949
}
50+
public void addSourceDescription(URL sourceDesc)
51+
{
52+
if (!ResourceSync.CAPABILITY_RESOURCESYNC.equals(sourceDesc.getCapability()))
53+
{
54+
throw new SpecComplianceException("URL added to ResourceSyncDescription is not a Capability List");
55+
}
56+
this.addUrl(sourceDesc);
57+
}
58+
public URL addSourceDescription(String loc)
59+
{
60+
return this.addSourceDescription(loc, null);
61+
}
62+
63+
public URL addSourceDescription(String loc, String describedby)
64+
{
65+
URL sourceDesc = new URL();
66+
sourceDesc.setLoc(loc);
67+
if (describedby != null)
68+
{
69+
sourceDesc.addLn(ResourceSync.REL_DESCRIBED_BY, describedby);
70+
}
71+
sourceDesc.setCapability(ResourceSync.CAPABILITY_RESOURCESYNC);
72+
this.addSourceDescription(sourceDesc);
73+
return sourceDesc;
74+
}
5075
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.openarchives.resourcesync;
2+
3+
public class ResourceSyncDescriptionIndex extends SitemapIndex{
4+
5+
public ResourceSyncDescriptionIndex(String capability) {
6+
super(capability);
7+
}
8+
9+
public void addSourceDescription(Sitemap sourceDesc)
10+
{
11+
if (!ResourceSync.CAPABILITY_RESOURCESYNC.equals(sourceDesc.getCapability()))
12+
// {
13+
// throw new SpecComplianceException("URL added to ResourceSyncDescription is not a Capability List");
14+
// }
15+
this.addSitemap(sourceDesc);
16+
}
17+
public Sitemap addSourceDescription(String loc)
18+
{
19+
return this.addSourceDescription(loc, null);
20+
}
21+
22+
public Sitemap addSourceDescription(String loc, String describedby)
23+
{
24+
Sitemap sourceDesc = new Sitemap();
25+
sourceDesc.setLoc(loc);
26+
if (describedby != null)
27+
{
28+
sourceDesc.addLn(ResourceSync.REL_DESCRIBED_BY, describedby);
29+
}
30+
// sourceDesc.setCapability(ResourceSync.CAPABILITY_RESOURCESYNC);
31+
this.addSourceDescription(sourceDesc);
32+
return sourceDesc;
33+
}
34+
35+
36+
37+
}

src/main/java/org/openarchives/resourcesync/ResourceSyncDocument.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,33 @@ public abstract class ResourceSyncDocument
2323
// these options should be provided by the extending class through the constructor overrides
2424
protected String capability;
2525
protected String root;
26-
26+
//ADD at and completed
27+
protected Date at;
28+
protected Date completed;
2729
// these options can be accessed using getters and setters
2830
protected Date from;
2931
protected Date until;
3032
protected List<ResourceSyncEntry> unorderedEntries = new ArrayList<ResourceSyncEntry>();
3133
protected TreeMap<Date, List<ResourceSyncEntry>> orderedEntries = new TreeMap<Date, List<ResourceSyncEntry>>();
3234
protected List<ResourceSyncLn> lns = new ArrayList<ResourceSyncLn>();
33-
35+
36+
private String changeType = null;
37+
38+
public String getChangeType() {
39+
return changeType;
40+
}
41+
42+
public void setChangeType(String changeType) {
43+
if (changeType.toLowerCase().equals("create")) {
44+
this.changeType = ResourceSync.CHANGE_CREATED;
45+
}else if (changeType.toLowerCase().equals("update")) {
46+
this.changeType = ResourceSync.CHANGE_UPDATED;
47+
}else if (changeType.toLowerCase().equals("delete")) {
48+
this.changeType = ResourceSync.CHANGE_DELETED;
49+
}
50+
}
51+
52+
3453
public ResourceSyncDocument(String root, String capability, InputStream in)
3554
{
3655
this.root = root;
@@ -133,7 +152,23 @@ public void setFromUntil(Date from, Date until)
133152
this.setUntil(until);
134153
}
135154

136-
public String getCapability()
155+
public Date getAt() {
156+
return this.at;
157+
}
158+
159+
public void setAt(Date at) {
160+
this.at = at;
161+
}
162+
163+
public Date getCompleted() {
164+
return this.completed;
165+
}
166+
167+
public void setCompleted(Date completed) {
168+
this.completed = completed;
169+
}
170+
171+
public String getCapability()
137172
{
138173
return capability;
139174
}
@@ -163,6 +198,8 @@ protected void populateDocument(Element element)
163198

164199
// - until
165200
String until = mdElement.getAttributeValue("until");
201+
202+
166203
if (until != null && !"".equals(until))
167204
{
168205
Date ud = ResourceSync.DATE_FORMAT.parse(until);
@@ -179,6 +216,7 @@ protected void populateDocument(Element element)
179216
if (rel != null && !"".equals(rel) && href != null && !"".equals(href))
180217
{
181218
this.addLn(rel, href);
219+
182220
}
183221
}
184222

@@ -240,6 +278,7 @@ public void serialise(OutputStream out)
240278
throws IOException
241279
{
242280
Element element = this.getElement();
281+
243282
Document doc = new Document(element);
244283
XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
245284
xmlOutputter.output(doc, out);

0 commit comments

Comments
 (0)