Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

recalculate DSSize after normalizing WSDL datastream or otherwise ass…

…igning new btye array (FCREPO-1173)
  • Loading branch information...
barmintor committed Dec 5, 2012
1 parent 609becc commit 29cfc30d9e08fa9c481b23a739628d8df7120eb2
@@ -12,12 +12,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import java.net.URI;
import java.net.URISyntaxException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@@ -26,31 +23,18 @@
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;

import org.apache.commons.betwixt.XMLUtils;

import org.apache.commons.io.IOUtils;

import org.jrdf.graph.URIReference;

import org.w3c.dom.Document;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.fcrepo.common.Constants;
import org.fcrepo.common.PID;
import org.fcrepo.common.rdf.SimpleURIReference;

import org.fcrepo.server.Context;
import org.fcrepo.server.RecoveryContext;
import org.fcrepo.server.Server;
@@ -88,6 +72,13 @@
import org.fcrepo.server.validation.ValidationUtility;
import org.fcrepo.server.validation.ecm.EcmValidator;
import org.fcrepo.utilities.DateUtility;
import org.jrdf.graph.URIReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;

/**
* Implements API-M without regard to the transport/messaging protocol.
@@ -148,6 +139,7 @@ public DefaultManagement(Authorization authz,
ecmValidator = new EcmValidator(doMgr,m_contentManager); //TODO, this should be controllable with the fcfg
}

@Override
public String ingest(Context context,
InputStream serialization,
String logMessage,
@@ -206,6 +198,7 @@ private void finishModification(DOWriter w, String method)
}
}

@Override
public Date modifyObject(Context context,
String pid,
String state,
@@ -281,6 +274,7 @@ public Date modifyObject(Context context,
}
}

@Override
public InputStream getObjectXML(Context context, String pid, String encoding)
throws ServerException {
try {
@@ -309,6 +303,7 @@ public InputStream getObjectXML(Context context, String pid, String encoding)
}
}

@Override
public InputStream export(Context context,
String pid,
String format,
@@ -346,6 +341,7 @@ public InputStream export(Context context,
}
}

@Override
public Date purgeObject(Context context,
String pid,
String logMessage) throws ServerException {
@@ -381,6 +377,7 @@ public Date purgeObject(Context context,
}
}

@Override
public String addDatastream(Context context,
String pid,
String dsID,
@@ -474,6 +471,7 @@ public String addDatastream(Context context,
// set and validate the content
DatastreamXMLMetadata dsm = (DatastreamXMLMetadata) ds;
dsm.xmlContent = getEmbeddableXML(in);
dsm.DSSize = dsm.xmlContent.length;
ValidationUtility.validateReservedDatastream(PID.getInstance(pid),
dsID,
dsm);
@@ -601,6 +599,7 @@ public String addDatastream(Context context,
}
}

@Override
public Date modifyDatastreamByReference(Context context,
String pid,
String datastreamId,
@@ -821,6 +820,7 @@ public Date modifyDatastreamByReference(Context context,
}
}

@Override
public Date modifyDatastreamByValue(Context context,
String pid,
String datastreamId,
@@ -1009,6 +1009,7 @@ public Date modifyDatastreamByValue(Context context,
}
}

@Override
public Date[] purgeDatastream(Context context,
String pid,
String datastreamID,
@@ -1136,6 +1137,7 @@ private String getPurgeLogMessage(String kindaThing,
return buf.toString();
}

@Override
public Datastream getDatastream(Context context,
String pid,
String datastreamID,
@@ -1168,6 +1170,7 @@ public Datastream getDatastream(Context context,
}
}

@Override
public Datastream[] getDatastreams(Context context,
String pid,
Date asOfDateTime,
@@ -1200,6 +1203,7 @@ public Datastream getDatastream(Context context,
}
}

@Override
public Datastream[] getDatastreamHistory(Context context,
String pid,
String datastreamID)
@@ -1245,6 +1249,7 @@ public Datastream getDatastream(Context context,
public class DatastreamDateComparator
implements Comparator<Object> {

@Override
public int compare(Object o1, Object o2) {
long ms1 = ((Datastream) o1).DSCreateDT.getTime();
long ms2 = ((Datastream) o1).DSCreateDT.getTime();
@@ -1258,6 +1263,7 @@ public int compare(Object o1, Object o2) {
}
}

@Override
public String[] getNextPID(Context context, int numPIDs, String namespace)
throws ServerException {
try {
@@ -1301,6 +1307,7 @@ public int compare(Object o1, Object o2) {
}
}

@Override
public String putTempStream(Context context, InputStream in)
throws StreamWriteException, AuthzException {
m_authz.enforceUpload(context);
@@ -1358,6 +1365,7 @@ private synchronized int getNextTempId(Context context) {
return m_lastId;
}

@Override
public InputStream getTempStream(String id) throws StreamReadException {
// it should come in starting with "uploaded://"
if (id.startsWith(DatastreamManagedContent.UPLOADED_SCHEME) || id.length() < 12) {
@@ -1378,6 +1386,7 @@ public InputStream getTempStream(String id) throws StreamReadException {
}
}

@Override
public Date setDatastreamState(Context context,
String pid,
String datastreamID,
@@ -1431,6 +1440,7 @@ public Date setDatastreamState(Context context,
}
}

@Override
public Date setDatastreamVersionable(Context context,
String pid,
String datastreamID,
@@ -1478,6 +1488,7 @@ public Date setDatastreamVersionable(Context context,
}
}

@Override
public String compareDatastreamChecksum(Context context,
String pid,
String datastreamID,
@@ -1647,6 +1658,7 @@ private static boolean isPid(String subject) {
}


@Override
public RelationshipTuple[] getRelationships(Context context,
String subject,
String relationship)
@@ -1695,6 +1707,7 @@ private static boolean isPid(String subject) {
}
}

@Override
public boolean addRelationship(Context context,
String subject,
String relationship,
@@ -1746,6 +1759,7 @@ public boolean addRelationship(Context context,
}
}

@Override
public boolean purgeRelationship(Context context,
String subject,
String relationship,
@@ -1805,6 +1819,7 @@ public boolean purgeRelationship(Context context,
* @return The result of the validation
* @see org.fcrepo.server.validation.ecm.EcmValidator
*/
@Override
public Validation validate(Context context,
String pid,
Date asOfDateTime) throws ServerException {
@@ -4,18 +4,20 @@
*/
package org.fcrepo.server.storage.translation;

import static org.fcrepo.common.Models.CONTENT_MODEL_3_0;
import static org.fcrepo.common.Models.FEDORA_OBJECT_3_0;
import static org.fcrepo.common.Models.SERVICE_DEFINITION_3_0;
import static org.fcrepo.common.Models.SERVICE_DEPLOYMENT_3_0;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;

import java.nio.charset.Charset;

import java.text.ParseException;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -48,11 +50,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.fcrepo.common.Models.CONTENT_MODEL_3_0;
import static org.fcrepo.common.Models.FEDORA_OBJECT_3_0;
import static org.fcrepo.common.Models.SERVICE_DEFINITION_3_0;
import static org.fcrepo.common.Models.SERVICE_DEPLOYMENT_3_0;

/**
* Utility methods for usage by digital object serializers and deserializers.
* This class provides methods for detecting various forms of relative
@@ -760,6 +757,7 @@ public static void normalizeDatastreams(DigitalObject obj,
"UTF-8"),
transContext)
.getBytes(characterEncoding);
xd.DSSize = xd.xmlContent.length;
}
}
}
@@ -5,18 +5,15 @@
import java.io.IOException;

import org.apache.commons.io.IOUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.fcrepo.common.Constants;

import org.fcrepo.server.Context;
import org.fcrepo.server.Module;
import org.fcrepo.server.Server;
import org.fcrepo.server.errors.ModuleInitializationException;
import org.fcrepo.server.errors.ServerInitializationException;
import org.fcrepo.server.errors.StreamIOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Wrapper class for a datastream that has XML metadata.
@@ -202,6 +199,7 @@ public Datastream getDatastream() {
public void setXMLContent(byte[] xmlContent) {
if (m_dsType == DS_TYPE.INLINE_XML) {
((DatastreamXMLMetadata)m_ds).xmlContent = xmlContent;
((DatastreamXMLMetadata)m_ds).DSSize = (xmlContent != null) ? xmlContent.length : -1;
} else if (m_dsType == DS_TYPE.MANAGED) {
ByteArrayInputStream bais = new ByteArrayInputStream(xmlContent);
MIMETypedStream s = new MIMETypedStream("text/xml", bais, null,xmlContent.length);

0 comments on commit 29cfc30

Please sign in to comment.
You can’t perform that action at this time.