private static Logger logger = Logger.getLogger(SaveMetadataAction.class);
public void doService() {
logger.debug("IN");
try {
IObjMetacontentDAO dao=DAOFactory.getObjMetacontentDAO();
dao.setUserProfile(getUserProfile());
Integer biobjectId = this.getAttributeAsInteger(OBJECT_ID);
logger.debug("Object id = " + biobjectId);
Integer subobjectId = null;
try {
subobjectId = this.getAttributeAsInteger(SUBOBJECT_ID);
} catch (NumberFormatException e) {}
logger.debug("Subobject id = " + subobjectId);
String jsonEncodedMetadata = getAttributeAsString( METADATA );
try {
CharsetDecoder decoder=Charset.forName("UTF-8").newDecoder();
jsonEncodedMetadata=decoder.decode(ByteBuffer.wrap(jsonEncodedMetadata.getBytes())).toString();
} catch(Throwable t) {
// firefox
}
logger.debug(METADATA + " = [" + jsonEncodedMetadata + "]");
JSONArray metadata = new JSONArray(jsonEncodedMetadata);
for (int i = 0; i < metadata.length(); i++) {
JSONObject aMetadata = metadata.getJSONObject(i);
Integer metadataId = aMetadata.getInt(MetadataJSONSerializer.METADATA_ID);
String text = aMetadata.getString(MetadataJSONSerializer.TEXT);
ObjMetacontent aObjMetacontent = dao.loadObjMetacontent(metadataId, biobjectId, subobjectId);
if (aObjMetacontent == null) {
logger.debug("ObjMetacontent for metadata id = " + metadataId + ", biobject id = " + biobjectId +
", subobject id = " + subobjectId + " was not found, creating a new one...");
aObjMetacontent = new ObjMetacontent();
aObjMetacontent.setObjmetaId(metadataId);
aObjMetacontent.setBiobjId(biobjectId);
aObjMetacontent.setSubobjId(subobjectId);
aObjMetacontent.setContent(text.getBytes("UTF-8"));
aObjMetacontent.setCreationDate(new Date());
aObjMetacontent.setLastChangeDate(new Date());
dao.insertObjMetacontent(aObjMetacontent);
} else {
logger.debug("ObjMetacontent for metadata id = " + metadataId + ", biobject id = " + biobjectId +
", subobject id = " + subobjectId + " was found, it will be modified...");
aObjMetacontent.setContent(text.getBytes("UTF-8"));
aObjMetacontent.setLastChangeDate(new Date());
dao.modifyObjMetacontent(aObjMetacontent);
}
}
/*
*indexes biobject by modifying document in index