Skip to content

Commit

Permalink
fixes #23 by adding the IPHeader and moving some existing elements in…
Browse files Browse the repository at this point in the history
…to it.
  • Loading branch information
chalkos authored and nuno-vieira-deel committed Mar 29, 2017
1 parent 07c793a commit 0105ece
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 23 deletions.
41 changes: 19 additions & 22 deletions src/main/java/org/roda_project/commons_ip/model/IP.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,26 @@

import javax.xml.datatype.XMLGregorianCalendar;

import org.roda_project.commons_ip.utils.IPEnums.IPStatus;
import org.roda_project.commons_ip.utils.IPEnums.IPType;
import org.roda_project.commons_ip.utils.IPException;
import org.roda_project.commons_ip.utils.METSEnums.CreatorType;
import org.roda_project.commons_ip.utils.Utils;
import org.roda_project.commons_ip.utils.ZipEntryInfo;
import org.roda_project.commons_ip.utils.IPEnums.IPStatus;
import org.roda_project.commons_ip.utils.IPEnums.IPType;
import org.roda_project.commons_ip.utils.METSEnums.CreatorType;

public abstract class IP implements IPInterface {

private List<String> ids;
private String profile;
private IPType type;
private Optional<XMLGregorianCalendar> createDate;
private Optional<XMLGregorianCalendar> modificationDate;
private IPHeader header;

private IPContentType contentType;
private IPStatus status;
private List<String> ancestors;

private Path basePath;
private String description;

private List<IPAgent> agents;
private List<IPDescriptiveMetadata> descriptiveMetadata;
private List<IPMetadata> preservationMetadata;
private List<IPMetadata> otherMetadata;
Expand All @@ -56,14 +54,13 @@ public IP() {
this.setId(Utils.generateRandomAndPrefixedUUID());
this.profile = "http://www.eark-project.com/METS/IP.xml";
this.type = IPType.SIP;
this.createDate = Utils.getCurrentTime();
this.header = new IPHeader();

this.contentType = IPContentType.getMIXED();
this.status = IPStatus.NEW;
this.ancestors = new ArrayList<>();

this.description = "";

this.agents = new ArrayList<IPAgent>();
this.descriptiveMetadata = new ArrayList<IPDescriptiveMetadata>();
this.preservationMetadata = new ArrayList<IPMetadata>();
this.otherMetadata = new ArrayList<IPMetadata>();
Expand All @@ -81,14 +78,15 @@ public IP(List<String> ipIds, IPType ipType) {
this.setIds(ipIds);
this.type = ipType;
this.zipEntries = new LinkedHashMap<String, ZipEntryInfo>();
this.header = new IPHeader();
}

public IP(List<String> ipIds, IPType ipType, IPContentType contentType, String creator) {
this(ipIds, ipType);
this.contentType = contentType;

IPAgent creatorAgent = new IPAgent(creator, "CREATOR", null, CreatorType.OTHER, "SOFTWARE");
this.agents.add(creatorAgent);
header.addAgent(creatorAgent);
}

@Override
Expand Down Expand Up @@ -137,23 +135,23 @@ public String getType() {

@Override
public Optional<XMLGregorianCalendar> getCreateDate() {
return createDate;
return header.getCreateDate();
}

@Override
public IP setCreateDate(XMLGregorianCalendar date) {
this.createDate = Optional.ofNullable(date);
header.setCreateDate(date);
return this;
}

@Override
public Optional<XMLGregorianCalendar> getModificationDate() {
return modificationDate;
return header.getModificationDate();
}

@Override
public IP setModificationDate(XMLGregorianCalendar date) {
this.modificationDate = Optional.ofNullable(date);
header.setModificationDate(date);
return this;
}

Expand Down Expand Up @@ -181,12 +179,12 @@ public IP setAncestors(List<String> ancestors) {

@Override
public IPStatus getStatus() {
return status;
return header.getStatus();
}

@Override
public IP setStatus(IPStatus status) {
this.status = status;
this.header.setStatus(status);
return this;
}

Expand Down Expand Up @@ -214,7 +212,7 @@ public String getDescription() {

@Override
public IP addAgent(IPAgent sipAgent) {
agents.add(sipAgent);
header.addAgent(sipAgent);
return this;
}

Expand Down Expand Up @@ -327,7 +325,7 @@ public IP addDocumentationToRepresentation(String representationID, IPFile docum

@Override
public List<IPAgent> getAgents() {
return agents;
return header.getAgents();
}

@Override
Expand Down Expand Up @@ -382,9 +380,8 @@ private void checkIfRepresentationExists(String representationID) throws IPExcep

@Override
public String toString() {
return "IP [ids=" + ids + ", profile=" + profile + ", type=" + type + ", createDate=" + createDate
+ ", modificationDate=" + modificationDate + ", contentType=" + contentType + ", status=" + status
+ ", ancestors=" + ancestors + ", basePath=" + basePath + ", description=" + description + ", agents=" + agents
return "IP [ids=" + ids + ", profile=" + profile + ", type=" + type + ", header=" + header + ", contentType="
+ contentType + ", ancestors=" + ancestors + ", basePath=" + basePath + ", description=" + description
+ ", descriptiveMetadata=" + descriptiveMetadata + ", preservationMetadata=" + preservationMetadata
+ ", otherMetadata=" + otherMetadata + ", representationIds=" + representationIds + ", representations="
+ representations + ", schemas=" + schemas + ", documentation=" + documentation + ", validationReport="
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/roda_project/commons_ip/model/IPAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public class IPAgent implements Serializable {
private CreatorType type;
private String otherRole;
private String otherType;
private String note;

public IPAgent() {
this.name = "";
this.role = "";
this.type = CreatorType.OTHER;
this.otherRole = "";
this.otherType = "";
this.note = "";
}

public IPAgent(String name, String role, String otherRole, CreatorType type, String otherType) {
Expand All @@ -34,6 +36,7 @@ public IPAgent(String name, String role, String otherRole, CreatorType type, Str
this.type = type;
this.otherRole = otherRole;
this.otherType = otherType;
this.note = "";
}

public String getName() {
Expand Down Expand Up @@ -81,10 +84,19 @@ public IPAgent setOtherType(String otherType) {
return this;
}

public String getNote() {
return note;
}

public IPAgent setNote(String note) {
this.note = note;
return this;
}

@Override
public String toString() {
return "IPAgent [name=" + name + ", role=" + role + ", type=" + type + ", otherRole=" + otherRole + ", otherType="
+ otherType + "]";
+ otherType + ", note=" + note + "]";
}

}
34 changes: 34 additions & 0 deletions src/main/java/org/roda_project/commons_ip/model/IPAltRecordID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.roda_project.commons_ip.model;

public class IPAltRecordID {
private String value;
private String type;

public IPAltRecordID() {
this.value = "";
this.type = "";
}

public String getValue() {
return value;
}

public IPAltRecordID setValue(String value) {
this.value = value;
return this;
}

public String getType() {
return type;
}

public IPAltRecordID setType(String type) {
this.type = type;
return this;
}

@Override
public String toString() {
return "IPAltRecordID [value=" + value + ", type=" + type + "]";
}
}
77 changes: 77 additions & 0 deletions src/main/java/org/roda_project/commons_ip/model/IPHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.roda_project.commons_ip.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import javax.xml.datatype.XMLGregorianCalendar;

import org.roda_project.commons_ip.utils.IPEnums;
import org.roda_project.commons_ip.utils.Utils;

public class IPHeader {
private Optional<XMLGregorianCalendar> createDate;
private Optional<XMLGregorianCalendar> modificationDate;
private IPEnums.IPStatus status;
private List<IPAgent> agents;
private List<IPAltRecordID> altRecordIDs;

public IPHeader() {
this.createDate = Utils.getCurrentTime();
this.modificationDate = Optional.empty();
this.status = IPEnums.IPStatus.NEW;
this.altRecordIDs = new ArrayList<>();
this.agents = new ArrayList<>();
}

public Optional<XMLGregorianCalendar> getCreateDate() {
return createDate;
}

public IPHeader setCreateDate(XMLGregorianCalendar date) {
this.createDate = Optional.ofNullable(date);
return this;
}

public Optional<XMLGregorianCalendar> getModificationDate() {
return modificationDate;
}

public IPHeader setModificationDate(XMLGregorianCalendar date) {
this.modificationDate = Optional.ofNullable(date);
return this;
}

public IPEnums.IPStatus getStatus() {
return status;
}

public IPHeader setStatus(IPEnums.IPStatus status) {
this.status = status;
return this;
}

public List<IPAltRecordID> getAltRecordIDs() {
return altRecordIDs;
}

public IPHeader addAltRecordID(IPAltRecordID altRecordID) {
altRecordIDs.add(altRecordID);
return this;
}

public List<IPAgent> getAgents() {
return agents;
}

public IPHeader addAgent(IPAgent sipAgent) {
agents.add(sipAgent);
return this;
}

@Override
public String toString() {
return "IPHeader [createDate=" + createDate + ", modificationDate=" + modificationDate + ", status=" + status
+ ", altRecordIDs=" + altRecordIDs + ", agents=" + agents + "]";
}
}

0 comments on commit 0105ece

Please sign in to comment.