* @param bean RetentionBean which encapsulates retention properties
* @return true if operation succeeds false otherwise
* @throws RegistryException
*/
public boolean setRetentionProperties(String path, RetentionBean bean) throws RegistryException {
UserRegistry registry = (UserRegistry) getRootRegistry();
if (RegistryUtils.isRegistryReadOnly(registry.getRegistryContext())) {
return false;
}
Resource resource = registry.get(path);
if (resource.getProperty(CommonConstants.RETENTION_USERNAME_PROP_NAME) != null &&
!resource.getProperty(CommonConstants.RETENTION_USERNAME_PROP_NAME).equals(
registry.getUserName())) {
throw new RegistryException("User is not authorized to change retention properties" +
" of this resource. Resource path = " + path);
}
if (bean == null) {
resource.removeProperty(CommonConstants.RETENTION_USERNAME_PROP_NAME);
resource.removeProperty(CommonConstants.RETENTION_FROM_DATE_PROP_NAME);
resource.removeProperty(CommonConstants.RETENTION_TO_DATE_PROP_NAME);
resource.removeProperty(CommonConstants.RETENTION_WRITE_LOCKED_PROP_NAME);
resource.removeProperty(CommonConstants.RETENTION_DELETE_LOCKED_PROP_NAME);
} else {
resource.setProperty(CommonConstants.RETENTION_USERNAME_PROP_NAME, registry.getUserName());
resource.setProperty(CommonConstants.RETENTION_FROM_DATE_PROP_NAME, bean.getFromDate());
resource.setProperty(CommonConstants.RETENTION_TO_DATE_PROP_NAME, bean.getToDate());
resource.setProperty(CommonConstants.RETENTION_WRITE_LOCKED_PROP_NAME,
String.valueOf(bean.getWriteLocked()));
resource.setProperty(CommonConstants.RETENTION_DELETE_LOCKED_PROP_NAME,
String.valueOf(bean.getDeleteLocked()));
}
registry.put(resource.getPath(), resource);
return true;
}