448 |
448 |
//String objectAsXML = "";
|
449 |
449 |
try {
|
450 |
450 |
//objectAsXML = IOUtils.toString(object, "UTF-8");
|
451 |
|
localId = insertOrUpdateDocument(object,"UTF-8", pid, session, "insert");
|
|
451 |
String formatId = null;
|
|
452 |
if(sysmeta.getFormatId() != null) {
|
|
453 |
formatId = sysmeta.getFormatId().getValue();
|
|
454 |
}
|
|
455 |
localId = insertOrUpdateDocument(object,"UTF-8", pid, session, "insert", formatId);
|
452 |
456 |
//localId = im.getLocalId(pid.getValue());
|
453 |
457 |
|
454 |
458 |
} catch (IOException e) {
|
... | ... | |
1303 |
1307 |
* @return localId - the resulting docid of the document created or updated
|
1304 |
1308 |
*
|
1305 |
1309 |
*/
|
1306 |
|
public String insertOrUpdateDocument(InputStream xml, String encoding, Identifier pid,
|
1307 |
|
Session session, String insertOrUpdate)
|
|
1310 |
public String insertOrUpdateDocument(InputStream xmlStream, String encoding, Identifier pid,
|
|
1311 |
Session session, String insertOrUpdate, String formatId)
|
1308 |
1312 |
throws ServiceFailure, IOException {
|
1309 |
1313 |
|
1310 |
1314 |
logMetacat.debug("Starting to insert xml document...");
|
... | ... | |
1312 |
1316 |
|
1313 |
1317 |
// generate pid/localId pair for sysmeta
|
1314 |
1318 |
String localId = null;
|
1315 |
|
byte[] xmlBytes = IOUtils.toByteArray(xml);
|
|
1319 |
byte[] xmlBytes = IOUtils.toByteArray(xmlStream);
|
|
1320 |
IOUtils.closeQuietly(xmlStream);
|
1316 |
1321 |
String xmlStr = new String(xmlBytes, encoding);
|
1317 |
1322 |
if(insertOrUpdate.equals("insert")) {
|
1318 |
1323 |
localId = im.generateLocalId(pid.getValue(), 1);
|
... | ... | |
1378 |
1383 |
// do the insert or update action
|
1379 |
1384 |
handler = new MetacatHandler(new Timer());
|
1380 |
1385 |
String result = handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), null,
|
1381 |
|
null, params, username, groupnames, false, false, xmlBytes);
|
|
1386 |
null, params, username, groupnames, false, false, xmlBytes, formatId);
|
1382 |
1387 |
|
1383 |
1388 |
if(result.indexOf("<error>") != -1) {
|
1384 |
1389 |
String detailCode = "";
|
... | ... | |
1415 |
1420 |
String[] groupnames = null;
|
1416 |
1421 |
if (session != null ) {
|
1417 |
1422 |
username = session.getSubject().getValue();
|
1418 |
|
if (session.getSubjectInfo() != null) {
|
1419 |
|
List<Group> groupList = session.getSubjectInfo().getGroupList();
|
1420 |
|
if (groupList != null) {
|
1421 |
|
groupnames = new String[groupList.size()];
|
1422 |
|
for (int i = 0; i < groupList.size(); i++ ) {
|
1423 |
|
groupnames[i] = groupList.get(i).getSubject().getValue();
|
1424 |
|
}
|
1425 |
|
}
|
|
1423 |
Set<Subject> otherSubjects = AuthUtils.authorizedClientSubjects(session);
|
|
1424 |
if (otherSubjects != null) {
|
|
1425 |
groupnames = new String[otherSubjects.size()];
|
|
1426 |
int i = 0;
|
|
1427 |
Iterator<Subject> iter = otherSubjects.iterator();
|
|
1428 |
while (iter.hasNext()) {
|
|
1429 |
groupnames[i] = iter.next().getValue();
|
|
1430 |
i++;
|
|
1431 |
}
|
1426 |
1432 |
}
|
1427 |
1433 |
}
|
1428 |
1434 |
|
... | ... | |
1503 |
1509 |
|
1504 |
1510 |
return localId;
|
1505 |
1511 |
|
1506 |
|
}
|
|
1512 |
}
|
1507 |
1513 |
|
1508 |
1514 |
/**
|
1509 |
1515 |
* Insert a systemMetadata document and return its localId
|
... | ... | |
1870 |
1876 |
*
|
1871 |
1877 |
* @throws ServiceFailure
|
1872 |
1878 |
*/
|
1873 |
|
private File writeStreamToFile(File dir, String fileName, InputStream data)
|
|
1879 |
private File writeStreamToFile(File dir, String fileName, InputStream dataStream)
|
1874 |
1880 |
throws ServiceFailure {
|
1875 |
1881 |
|
1876 |
1882 |
File newFile = new File(dir, fileName);
|
... | ... | |
1880 |
1886 |
if (newFile.createNewFile()) {
|
1881 |
1887 |
// write data stream to desired file
|
1882 |
1888 |
OutputStream os = new FileOutputStream(newFile);
|
1883 |
|
long length = IOUtils.copyLarge(data, os);
|
|
1889 |
long length = IOUtils.copyLarge(dataStream, os);
|
1884 |
1890 |
os.flush();
|
1885 |
1891 |
os.close();
|
1886 |
1892 |
} else {
|
... | ... | |
1895 |
1901 |
logMetacat.debug("IOE: " + e.getMessage());
|
1896 |
1902 |
throw new ServiceFailure("1190", "File was not written: " + fileName
|
1897 |
1903 |
+ " " + e.getMessage());
|
|
1904 |
} finally {
|
|
1905 |
IOUtils.closeQuietly(dataStream);
|
1898 |
1906 |
}
|
1899 |
1907 |
|
1900 |
1908 |
return newFile;
|
correct two minor differences from 2.6 merge: formatId parameter for MetacatHandler and using AuthUtils for gathering group membership information.