//the metadata may define the ID for the contentItem
//only used if not parsed as query param
if(contentItemId == null && fis.getName() != null && !fis.getName().isEmpty()){
contentItemId = new UriRef(fis.getName());
}
metadata = new IndexedMGraph();
try {
getParser().parse(metadata, fis.openStream(), fis.getContentType());
} catch (Exception e) {
throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST)
.entity(String.format("Unable to parse Metadata " +
"from Multipart MIME part '%s' (" +
"contentItem: %s| contentType: %s)",
fis.getFieldName(),fis.getName(),fis.getContentType()))
.build());
}
} else if(fis.getFieldName().equals("content")){
contentItem = createContentItem(contentItemId, metadata, fis, parsedContentIds);
} else if(fis.getFieldName().equals("properties") ||
fis.getFieldName().equals(ENHANCEMENT_PROPERTIES_URI.getUnicodeString())){
//parse the enhancementProperties
if(contentItem == null){
throw new WebApplicationException(
Response.status(Response.Status.BAD_REQUEST)
.entity("Multipart MIME parts for " +
"EnhancementProperties MUST BE after the " +
"MIME parts for 'metadata' AND 'content'")
.build());
}
MediaType propMediaType = MediaType.valueOf(fis.getContentType());
if(!APPLICATION_JSON_TYPE.isCompatible(propMediaType)){
throw new WebApplicationException(
Response.status(Response.Status.BAD_REQUEST)
.entity("EnhancementProperties (Multipart MIME parts" +
"with the name '"+fis.getFieldName()+"') MUST " +
"BE encoded as 'appicaltion/json' (encountered: '" +
fis.getContentType()+"')!")
.build());
}
String propCharset = propMediaType.getParameters().get("charset");
if(propCharset == null){
propCharset = "UTF-8";
}
Map<String,Object> enhancementProperties = getEnhancementProperties(contentItem);
try {
enhancementProperties.putAll(toMap(new JSONObject(
IOUtils.toString(fis.openStream(),propCharset))));
} catch (JSONException e) {
throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST)
.entity("Unable to parse EnhancementProperties from" +
"Multipart MIME parts with the name 'properties'!")
.build());
}
} else { //additional metadata as serialised RDF
if(contentItem == null){
throw new WebApplicationException(
Response.status(Response.Status.BAD_REQUEST)
.entity("Multipart MIME parts for additional " +
"contentParts MUST BE after the MIME " +
"parts for 'metadata' AND 'content'")
.build());
}
if(fis.getFieldName() == null || fis.getFieldName().isEmpty()){
throw new WebApplicationException(
Response.status(Response.Status.BAD_REQUEST)
.entity("Multipart MIME parts representing " +
"ContentParts for additional RDF metadata" +
"MUST define the contentParts URI as" +
"'name' of the MIME part!").build());
}
MGraph graph = new IndexedMGraph();
try {
getParser().parse(graph, fis.openStream(), fis.getContentType());
} catch (Exception e) {
throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST)