Adding support to set last-updater on header refs #9999

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@157628 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-10-26 15:28:11 +00:00
parent 56a36499cd
commit a39495bdd0
1 changed files with 31 additions and 15 deletions

View File

@ -36,6 +36,25 @@ public class HeaderUtility {
private static final Logger logger = LoggerFactory
.getLogger(HeaderUtility.class);
public static String getUser() {
String user = org.gcube.informationsystem.model.embedded.Header.UNKNOWN_USER;
try {
Caller caller = AuthorizationProvider.instance.get();
if(caller!=null){
ClientInfo clientInfo = caller.getClient();
String clientId = clientInfo.getId();
if (clientId != null && clientId.compareTo("") != 0) {
user = clientId;
} else {
throw new Exception("Username null or empty");
}
}
} catch (Exception e) {
logger.error("Unable to retrieve user. {} will be used", user);
}
return user;
}
public static Header createHeader(UUID uuid) {
HeaderOrient header = new HeaderOrient();
@ -45,21 +64,7 @@ public class HeaderUtility {
header.setUUID(uuid);
String creator = org.gcube.informationsystem.model.embedded.Header.UNKNOWN_USER;
try {
Caller caller = AuthorizationProvider.instance.get();
if(caller!=null){
ClientInfo clientInfo = caller.getClient();
String clientId = clientInfo.getId();
if (clientId != null && clientId.compareTo("") != 0) {
creator = clientId;
} else {
throw new Exception("Username null or empty");
}
}
} catch (Exception e) {
logger.error("Unable to retrieve user. {} will be used", creator);
}
String creator = getUser();
header.setCreator(creator);
header.setLastUpdater(creator);
@ -132,4 +137,15 @@ public class HeaderUtility {
return Utility.getEmbedded(Header.class, element, Entity.HEADER_PROPERTY);
}
public static Header updateLastUpdateAndLastUpdater(Element element) throws ResourceRegistryException {
HeaderOrient headerOrient = getHeaderOrient(element.getProperty(Entity.HEADER_PROPERTY));
String lastUpdater = getUser();
headerOrient.setLastUpdater(lastUpdater);
Date lastUpdateTime = Calendar.getInstance().getTime();
headerOrient.setLastUpdateTime(lastUpdateTime);
headerOrient.save();
return headerOrient;
}
}