Merge pull request #1256 from KevinVdV/DS-3008-fix-metadata-order

[DS-3008] Fix metadata order storage
This commit is contained in:
helix84
2016-01-31 02:31:13 +01:00
9 changed files with 53 additions and 1 deletions

View File

@@ -215,7 +215,7 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl<Bitstream> imp
log.info(LogManager.getHeader(context, "update_bitstream", log.info(LogManager.getHeader(context, "update_bitstream",
"bitstream_id=" + bitstream.getID())); "bitstream_id=" + bitstream.getID()));
super.update(context, bitstream);
if (bitstream.isModified()) if (bitstream.isModified())
{ {
context.addEvent(new Event(Event.MODIFY, Constants.BITSTREAM, bitstream.getID(), null, getIdentifiers(context, bitstream))); context.addEvent(new Event(Event.MODIFY, Constants.BITSTREAM, bitstream.getID(), null, getIdentifiers(context, bitstream)));

View File

@@ -361,6 +361,7 @@ public class BundleServiceImpl extends DSpaceObjectServiceImpl<Bundle> implement
log.info(LogManager.getHeader(context, "update_bundle", "bundle_id=" log.info(LogManager.getHeader(context, "update_bundle", "bundle_id="
+ bundle.getID())); + bundle.getID()));
super.update(context, bundle);
bundleDAO.save(context, bundle); bundleDAO.save(context, bundle);
if (bundle.isModified() || bundle.isMetadataModified()) if (bundle.isModified() || bundle.isMetadataModified())

View File

@@ -566,6 +566,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
log.info(LogManager.getHeader(context, "update_collection", log.info(LogManager.getHeader(context, "update_collection",
"collection_id=" + collection.getID())); "collection_id=" + collection.getID()));
super.update(context, collection);
collectionDAO.save(context, collection); collectionDAO.save(context, collection);
if (collection.isModified()) if (collection.isModified())

View File

@@ -235,6 +235,8 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
log.info(LogManager.getHeader(context, "update_community", log.info(LogManager.getHeader(context, "update_community",
"community_id=" + community.getID())); "community_id=" + community.getID()));
super.update(context, community);
communityDAO.save(context, community); communityDAO.save(context, community);
if (community.isModified()) if (community.isModified())
{ {

View File

@@ -11,6 +11,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.authority.Choices; import org.dspace.content.authority.Choices;
import org.dspace.content.authority.service.ChoiceAuthorityService; import org.dspace.content.authority.service.ChoiceAuthorityService;
import org.dspace.content.authority.service.MetadataAuthorityService; import org.dspace.content.authority.service.MetadataAuthorityService;
@@ -532,6 +533,44 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
} }
} }
@Override
public void update(Context context, T dso) throws SQLException, AuthorizeException
{
if(dso.isMetadataModified())
{
/*
Update the order of the metadata values
*/
// A map created to store the latest place for each metadata field
Map<MetadataField, Integer> fieldToLastPlace = new HashMap<>();
List<MetadataValue> metadataValues = dso.getMetadata();
for (MetadataValue metadataValue : metadataValues)
{
//Retrieve & store the place for each metadata value
int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue);
metadataValue.setPlace(mvPlace);
}
}
}
/**
* Retrieve the place of the metadata value
* @param fieldToLastPlace the map containing the latest place of each metadata field
* @param metadataValue the metadata value that needs to get a place
* @return The new place for the metadata valu
*/
protected int getMetadataValuePlace(Map<MetadataField, Integer> fieldToLastPlace, MetadataValue metadataValue) {
MetadataField metadataField = metadataValue.getMetadataField();
if(fieldToLastPlace.containsKey(metadataField))
{
fieldToLastPlace.put(metadataField, fieldToLastPlace.get(metadataField) + 1);
}else{
// The metadata value place starts at 0
fieldToLastPlace.put(metadataField, 0);
}
return fieldToLastPlace.get(metadataField);
}
protected String[] getMDValueByLegacyField(String field){ protected String[] getMDValueByLegacyField(String field){
switch (field) { switch (field) {
case "introductory_text": case "introductory_text":

View File

@@ -413,6 +413,8 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
log.info(LogManager.getHeader(context, "update_item", "item_id=" log.info(LogManager.getHeader(context, "update_item", "item_id="
+ item.getID())); + item.getID()));
super.update(context, item);
// Set sequence IDs for bitstreams in item // Set sequence IDs for bitstreams in item
int sequence = 0; int sequence = 0;
List<Bundle> bunds = item.getBundles(); List<Bundle> bunds = item.getBundles();

View File

@@ -72,6 +72,9 @@ public class SiteServiceImpl extends DSpaceObjectServiceImpl<Site> implements Si
if(!authorizeService.isAdmin(context)){ if(!authorizeService.isAdmin(context)){
throw new AuthorizeException(); throw new AuthorizeException();
} }
super.update(context, site);
if(site.isMetadataModified()) if(site.isMetadataModified())
{ {
context.addEvent(new Event(Event.MODIFY_METADATA, site.getType(), site.getID(), site.getDetails(), getIdentifiers(context, site))); context.addEvent(new Event(Event.MODIFY_METADATA, site.getType(), site.getID(), site.getDetails(), getIdentifiers(context, site)));

View File

@@ -318,6 +318,8 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
authorizeService.authorizeAction(context, ePerson, Constants.WRITE); authorizeService.authorizeAction(context, ePerson, Constants.WRITE);
} }
super.update(context, ePerson);
ePersonDAO.save(context, ePerson); ePersonDAO.save(context, ePerson);
log.info(LogManager.getHeader(context, "update_eperson", log.info(LogManager.getHeader(context, "update_eperson",

View File

@@ -388,6 +388,8 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
@Override @Override
public void update(Context context, Group group) throws SQLException, AuthorizeException public void update(Context context, Group group) throws SQLException, AuthorizeException
{ {
super.update(context, group);
// FIXME: Check authorisation // FIXME: Check authorisation
groupDAO.save(context, group); groupDAO.save(context, group);