Refs #9999: Add modifiedBy in header of entities and relations

Task-Url: https://support.d4science.org/issues/9999

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158401 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-11-13 11:41:41 +00:00
parent ecbe981112
commit 4431d0f364
3 changed files with 24 additions and 45 deletions

View File

@ -356,11 +356,9 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
public El internalUpdate() throws ERNotFoundException, ResourceRegistryException { public El internalUpdate() throws ERNotFoundException, ResourceRegistryException {
try { try {
reallyUpdate(); reallyUpdate();
HeaderUtility.updateModifiedByAndLastUpdate(element);
// TODO update lastUpdater and lastUpdatetime
((OrientVertex) element).save(); ((OrientVertex) element).save();
return element; return element;
}catch (ResourceRegistryException e) { }catch (ResourceRegistryException e) {
throw e; throw e;
@ -391,11 +389,8 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
public boolean internalAddToContext() throws ContextException, ResourceRegistryException { public boolean internalAddToContext() throws ContextException, ResourceRegistryException {
try { try {
boolean ret = reallyAddToContext(); boolean ret = reallyAddToContext();
HeaderUtility.updateModifiedByAndLastUpdate(element);
// TODO update lastUpdater and lastUpdatetime
((OrientVertex) element).save(); ((OrientVertex) element).save();
return ret && true; return ret && true;
}catch (ResourceRegistryException e) { }catch (ResourceRegistryException e) {
throw e; throw e;
@ -410,11 +405,8 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
public boolean internalRemoveFromContext() throws ContextException, ResourceRegistryException { public boolean internalRemoveFromContext() throws ContextException, ResourceRegistryException {
try { try {
boolean ret = reallyRemoveFromContext(); boolean ret = reallyRemoveFromContext();
HeaderUtility.updateModifiedByAndLastUpdate(element);
// TODO update lastUpdater and lastUpdatetime
((OrientVertex) element).save(); ((OrientVertex) element).save();
return ret && true; return ret && true;
}catch (ResourceRegistryException e) { }catch (ResourceRegistryException e) {
throw e; throw e;
@ -621,18 +613,14 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
public String update() throws ERNotFoundException, public String update() throws ERNotFoundException,
ERAvailableInAnotherContextException, ResourceRegistryException { ERAvailableInAnotherContextException, ResourceRegistryException {
try { try {
orientGraph = ContextUtility orientGraph = ContextUtility
.getActualSecurityContextGraph(PermissionMode.WRITER); .getActualSecurityContextGraph(PermissionMode.WRITER);
element = internalUpdate(); element = internalUpdate();
orientGraph.commit(); orientGraph.commit();
// TODO Notify to subscriptionNotification // TODO Notify to subscriptionNotification
return serialize(); return serialize();
// TODO Serialized resource is the old version. This really strange and should be an orient bug // TODO Serialized resource is the old version. This really strange and should be an orient bug
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
@ -657,14 +645,10 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid); logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
try { try {
/*
orientGraph = ContextUtility
.getActualSecurityContextGraph(PermissionMode.WRITER);
*/
orientGraph = SecurityContextMapper.getSecurityContextFactory( orientGraph = SecurityContextMapper.getSecurityContextGraph(
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
PermissionMode.WRITER).getTx(); PermissionMode.WRITER);
boolean deleted = reallyDelete(); boolean deleted = reallyDelete();
@ -704,11 +688,11 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
accessType.getName(), uuid); accessType.getName(), uuid);
try { try {
orientGraph = SecurityContextMapper.getSecurityContextFactory( orientGraph = SecurityContextMapper.getSecurityContextGraph(
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
PermissionMode.WRITER).getTx(); PermissionMode.WRITER);
boolean added = reallyAddToContext(); boolean added = internalAddToContext();
orientGraph.commit(); orientGraph.commit();
logger.info("{} with UUID {} successfully added to actual Context", logger.info("{} with UUID {} successfully added to actual Context",
@ -734,11 +718,11 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
accessType.getName(), uuid); accessType.getName(), uuid);
try { try {
orientGraph = SecurityContextMapper.getSecurityContextFactory( orientGraph = SecurityContextMapper.getSecurityContextGraph(
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
PermissionMode.WRITER).getTx(); PermissionMode.WRITER);
boolean removed = reallyRemoveFromContext(); boolean removed = internalRemoveFromContext();
orientGraph.commit(); orientGraph.commit();
logger.info( logger.info(

View File

@ -52,12 +52,12 @@ public class HeaderOrient extends ODocument implements org.gcube.informationsyst
} }
@Override @Override
public String getLastUpdater() { public String getModifiedBy() {
return this.field(Header.LAST_UPDATER_PROPERTY); return this.field(Header.MODIFIED_BY_PROPERTY);
} }
public void setLastUpdater(String lastUpdater){ public void setModifiedBy(String modifiedBy){
this.field(Header.LAST_UPDATER_PROPERTY, lastUpdater); this.field(Header.MODIFIED_BY_PROPERTY, modifiedBy);
} }
@Override @Override

View File

@ -29,7 +29,6 @@ import com.tinkerpop.blueprints.Element;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*
*/ */
public class HeaderUtility { public class HeaderUtility {
@ -66,7 +65,7 @@ public class HeaderUtility {
String creator = getUser(); String creator = getUser();
header.setCreator(creator); header.setCreator(creator);
header.setLastUpdater(creator); header.setModifiedBy(creator);
Date date = Calendar.getInstance().getTime(); Date date = Calendar.getInstance().getTime();
SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
@ -110,7 +109,7 @@ public class HeaderUtility {
headerOrient.setUUID(header.getUUID()); headerOrient.setUUID(header.getUUID());
headerOrient.setCreator(header.getCreator()); headerOrient.setCreator(header.getCreator());
headerOrient.setCreationTime(header.getCreationTime()); headerOrient.setCreationTime(header.getCreationTime());
headerOrient.setLastUpdater(header.getLastUpdater()); headerOrient.setModifiedBy(header.getModifiedBy());
headerOrient.setLastUpdateTime(header.getLastUpdateTime()); headerOrient.setLastUpdateTime(header.getLastUpdateTime());
return headerOrient; return headerOrient;
} catch (Exception e) { } catch (Exception e) {
@ -125,7 +124,6 @@ public class HeaderUtility {
return header; return header;
} }
public static Header addHeader(Edge edge, UUID uuid) { public static Header addHeader(Edge edge, UUID uuid) {
Header header = createHeader(uuid); Header header = createHeader(uuid);
edge.setProperty(Entity.HEADER_PROPERTY, header); edge.setProperty(Entity.HEADER_PROPERTY, header);
@ -137,15 +135,12 @@ public class HeaderUtility {
return Utility.getEmbedded(Header.class, element, Entity.HEADER_PROPERTY); return Utility.getEmbedded(Header.class, element, Entity.HEADER_PROPERTY);
} }
public static void updateModifiedByAndLastUpdate(Element element) throws ResourceRegistryException {
public static Header updateLastUpdateAndLastUpdater(Element element) throws ResourceRegistryException { ODocument oDocument = element.getProperty(Entity.HEADER_PROPERTY);
HeaderOrient headerOrient = getHeaderOrient(element.getProperty(Entity.HEADER_PROPERTY)); String modifiedBy = getUser();
String lastUpdater = getUser(); oDocument.field(Header.MODIFIED_BY_PROPERTY, modifiedBy);
headerOrient.setLastUpdater(lastUpdater);
Date lastUpdateTime = Calendar.getInstance().getTime(); Date lastUpdateTime = Calendar.getInstance().getTime();
headerOrient.setLastUpdateTime(lastUpdateTime); oDocument.field(Header.LAST_UPDATE_TIME_PROPERTY, lastUpdateTime);
headerOrient.save();
return headerOrient;
} }
} }