Collection col = Collection.find(context, collectionId);
if (col != null) {
Item item = prepareItem(context, col, (HashMap) inputVar);
return String.valueOf(item.getID());
} else {
throw new EntityException("Internal server error", "Could not create item", 500);
}
} else {
throw new EntityException("Internal server error", "Could not create item", 500);
}
} else if(inputVar instanceof InputStream) { //zip
Map<String, InputStream> fileMap = new HashMap<String, InputStream>();
Map xmlMap = new HashMap();
ZipInputStream zipInputStream = new ZipInputStream((InputStream) inputVar);
ZipEntry zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null) {
if ("package.xml".equalsIgnoreCase(zipEntry.getName())) {
xmlMap = (Map) Utils.translateFormattedData("xml", zipInputStream);
} else {
InputStream nis = Utils.transferInputStream(zipInputStream);
fileMap.put(zipEntry.getName(), nis);
}
zipEntry = zipInputStream.getNextEntry();
}
collectionId = Integer.parseInt((String) xmlMap.get("collectionId"));
if (collectionId > 0) {
Collection col = Collection.find(context, collectionId);
if (col != null) {
Item item = prepareItem(context, col, xmlMap);
List<Map> bundleList = getNodeList(xmlMap, "bundles", "bundle");
for (Map bundleMap : bundleList) {
String bundleName = (String) bundleMap.get("name");
Bundle bundle = item.createBundle(bundleName);
List<Map> bitstreamList = getNodeList(bundleMap, "bitstreams", "bitstream");
int sequence = 1;
for (Map bitstreamMap : bitstreamList) {
String bitstreamName = (String) bitstreamMap.get("name");
String mimeType = (String) bitstreamMap.get("mimeType");
String description = (String) bitstreamMap.get("description");
String primary = (String) bitstreamMap.get("primary");
BitstreamFormat bitstreamFormat = BitstreamFormat.findByMIMEType(context, mimeType);
Bitstream bitstream = bundle.createBitstream(fileMap.get(bitstreamName));
bitstream.setName(bitstreamName);
bitstream.setDescription(description);
bitstream.setSequenceID(sequence++);
bitstream.setFormat(bitstreamFormat);
bitstream.setSource(bitstreamName);
bitstream.update();
if ("true".equals(primary)) {
bundle.setPrimaryBitstreamID(bitstream.getID());
bundle.update();
}
}
}
item.update();
//bundle package
context.addEvent(new Event(Event.INSTALL, Constants.ITEM, item.getID(),null));
return String.valueOf(item.getID());
} else {
throw new EntityException("Internal server error", "Could not create item", 500);
}
} else {
throw new EntityException("Internal server error", "Could not create item", 500);
}
} else {
throw new EntityException("Internal server error", "Could not create item", 500);
}
// } else {
// throw new EntityException("Internal server error", "Could not create item", 500);
// }
} catch (SQLException ex) {
throw new EntityException("Internal server error", "SQL error", 500);
} catch (AuthorizeException ae) {
throw new EntityException("Forbidden", "Forbidden", 403);
} catch (IOException ie) {
throw new EntityException("Internal server error", "SQL error, cannot create item", 500);
} catch (NumberFormatException ex) {
throw new EntityException("Bad request", "Could not parse input", 400);
// } catch (SAXException e) {
// throw new EntityException("Bad request", "Could not parse SAX", 400);
// } catch (ParserConfigurationException e) {
// throw new EntityException("Bad request", "Could not parse SAX", 400);
}