* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.models.pdp.persistence.concepts;
+import jakarta.persistence.Column;
+import jakarta.persistence.EmbeddedId;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Inheritance;
+import jakarta.persistence.InheritanceType;
+import jakarta.persistence.Table;
+import jakarta.persistence.Temporal;
+import jakarta.persistence.TemporalType;
+import java.io.Serial;
import java.io.Serializable;
+import java.util.Date;
import java.util.List;
-import javax.persistence.Column;
-import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
-import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.builder.CompareToBuilder;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
@Data
@EqualsAndHashCode(callSuper = false)
public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializable {
+ @Serial
private static final long serialVersionUID = -357224425637789775L;
@EmbeddedId
@NotBlank
private String message;
+ @Column(precision = 0)
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date lastUpdate;
+
/**
* The Default Constructor creates a {@link JpaPdp} object with a null key.
*/
* @param healthy the health state of the PDP
*/
public JpaPdp(@NonNull final PfReferenceKey key, @NonNull final PdpState pdpState,
- @NonNull PdpHealthStatus healthy) {
+ @NonNull PdpHealthStatus healthy) {
this.key = key;
this.pdpState = pdpState;
this.healthy = healthy;
+ this.lastUpdate = new Date();
}
/**
this.pdpState = copyConcept.pdpState;
this.healthy = copyConcept.healthy;
this.message = copyConcept.message;
+ this.lastUpdate = copyConcept.lastUpdate;
}
/**
pdp.setPdpState(pdpState);
pdp.setHealthy(healthy);
pdp.setMessage(message);
+ pdp.setLastUpdate(lastUpdate.toInstant());
return pdp;
}
this.setPdpState(pdp.getPdpState());
this.setHealthy(pdp.getHealthy());
this.setMessage(pdp.getMessage());
+
+ if (pdp.getLastUpdate() == null) {
+ this.setLastUpdate(new Date());
+ } else {
+ this.setLastUpdate(Date.from(pdp.getLastUpdate()));
+ }
}
@Override
}
final JpaPdp other = (JpaPdp) otherConcept;
- if (!key.equals(other.key)) {
- return key.compareTo(other.key);
- }
-
- int result = ObjectUtils.compare(pdpState, other.pdpState);
- if (result != 0) {
- return result;
- }
-
- result = ObjectUtils.compare(healthy, other.healthy);
- if (result != 0) {
- return result;
- }
- return ObjectUtils.compare(message, other.message);
+ // @formatter:off
+ return new CompareToBuilder()
+ .append(this.key, other.key)
+ .append(this.pdpState, other.pdpState)
+ .append(this.healthy, other.healthy)
+ .append(this.message, other.message)
+ .append(this.lastUpdate, other.lastUpdate)
+ .toComparison();
+ // @formatter:on
}
}