Added Optional Message to support AccessLogger library fields for PortletUsageRecord
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115295 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
37cf5f721d
commit
3164a8e66c
|
@ -4,14 +4,22 @@
|
||||||
package org.gcube.accounting.datamodel.implementations;
|
package org.gcube.accounting.datamodel.implementations;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||||
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
|
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
||||||
|
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
||||||
import org.gcube.accounting.datamodel.decorators.RequiredField;
|
import org.gcube.accounting.datamodel.decorators.RequiredField;
|
||||||
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
|
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
|
||||||
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
|
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
|
||||||
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
|
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
|
||||||
|
import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator;
|
||||||
import org.gcube.accounting.exception.InvalidValueException;
|
import org.gcube.accounting.exception.InvalidValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,8 +33,21 @@ public class PortletUsageRecord extends RawUsageRecord implements SingleUsageRec
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 8339324883678974869L;
|
private static final long serialVersionUID = 8339324883678974869L;
|
||||||
|
|
||||||
@NotEmptyIfNotNull @DeprecatedWarning
|
@DeprecatedWarning @MoveToConsumerId
|
||||||
protected static final String USER_ID = "userId";
|
protected static final String USER_ID = "userId";
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@FieldDecorator(managed=MoveToConsumerIdAction.class)
|
||||||
|
protected @interface MoveToConsumerId { }
|
||||||
|
protected class MoveToConsumerIdAction implements FieldAction {
|
||||||
|
@Override
|
||||||
|
public Serializable validate(String key, Serializable value, UsageRecord usageRecord) throws InvalidValueException {
|
||||||
|
NotEmptyIfNotNullValidator neinnv = new NotEmptyIfNotNullValidator();
|
||||||
|
value = neinnv.validate(key, value, usageRecord);
|
||||||
|
usageRecord.setConsumerId((String) value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@RequiredField @NotEmpty
|
@RequiredField @NotEmpty
|
||||||
public static final String PORTLET_ID = "portletId";
|
public static final String PORTLET_ID = "portletId";
|
||||||
|
@ -43,14 +64,25 @@ public class PortletUsageRecord extends RawUsageRecord implements SingleUsageRec
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use {@link #getConsumerId()} instead
|
||||||
|
* @return the Consumer ID
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String getUserId() {
|
public String getUserId() {
|
||||||
return (String) this.resourceProperties.get(USER_ID);
|
return (String) this.resourceProperties.get(CONSUMER_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If correct,ly set is a duplicated for Consumer Id, use
|
||||||
|
* {@link #setConsumerId()} instead.
|
||||||
|
* @param userId Consumer Id
|
||||||
|
* @throws InvalidValueException if fails
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setUserId(String userId) throws InvalidValueException {
|
public void setUserId(String userId) throws InvalidValueException {
|
||||||
setResourceProperty(USER_ID, userId);
|
setResourceProperty(USER_ID, userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPortletId() {
|
public String getPortletId() {
|
||||||
|
|
Loading…
Reference in New Issue