}
try
{
// Update the metadata for a DC type
MetadataField dc = MetadataField.find(context, UIUtil
.getIntParameter(request, "dc_type_id"));
dc.setElement(request.getParameter("element"));
String qual = request.getParameter("qualifier");
if (qual.equals(""))
{
qual = null;
}
dc.setQualifier(qual);
dc.setScopeNote(request.getParameter("scope_note"));
dc.update(context);
showTypes(context, request, response, schemaID);
context.complete();
}
catch (NonUniqueMetadataException e)
{
context.abort();
log.error(e);
}
}
else if (button.equals("submit_add"))
{
// The sanity check will update the request error string if needed
if (!sanityCheck(request, labels))
{
showTypes(context, request, response, schemaID);
context.abort();
return;
}
// Add a new DC type - simply add to the list, and let the user
// edit with the main form
try
{
MetadataField dc = new MetadataField();
dc.setSchemaID(schemaID);
dc.setElement(request.getParameter("element"));
String qual = request.getParameter("qualifier");
if (qual.equals(""))
{
qual = null;
}
dc.setQualifier(qual);
dc.setScopeNote(request.getParameter("scope_note"));
dc.create(context);
showTypes(context, request, response, schemaID);
context.complete();
}
catch (NonUniqueMetadataException e)
{
// Record the exception as a warning
log.warn(e);
// Show the page again but with an error message to inform the
// user that the metadata field was not created and why
request.setAttribute("error", labels.getString(clazz
+ ".createfailed"));
showTypes(context, request, response, schemaID);
context.abort();
}
}
else if (button.equals("submit_delete"))
{
// Start delete process - go through verification step
MetadataField dc = MetadataField.find(context, UIUtil
.getIntParameter(request, "dc_type_id"));
request.setAttribute("type", dc);
JSPManager.showJSP(request, response,
"/dspace-admin/confirm-delete-mdfield.jsp");
}
else if (button.equals("submit_confirm_delete"))
{
// User confirms deletion of type
MetadataField dc = MetadataField.find(context, UIUtil
.getIntParameter(request, "dc_type_id"));
try
{
dc.delete(context);
request.setAttribute("failed", new Boolean(false));
showTypes(context, request, response, schemaID);
} catch (Exception e)
{
request.setAttribute("type", dc);
request.setAttribute("failed", true);
JSPManager.showJSP(request, response,
"/dspace-admin/confirm-delete-mdfield.jsp");
}
context.complete();
}
else if (button.equals("submit_move"))
{
// User requests that one or more metadata elements be moved to a
// new metadata schema. Note that we change the default schema ID to
// be the destination schema.
try
{
schemaID = Integer.parseInt(request
.getParameter("dc_dest_schema_id"));
String[] param = request.getParameterValues("dc_field_id");
if (schemaID == 0 || param == null)
{
request.setAttribute("error", labels.getString(clazz
+ ".movearguments"));
showTypes(context, request, response, schemaID);
context.abort();
}
else
{
for (int ii = 0; ii < param.length; ii++)
{
int fieldID = Integer.parseInt(param[ii]);
MetadataField field = MetadataField.find(context,
fieldID);
field.setSchemaID(schemaID);
field.update(context);
}
context.complete();
// Send the user to the metadata schema in which they just moved