gcube-cms-suite/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/document/Project.java

114 lines
4.0 KiB
Java
Raw Normal View History

2021-11-24 14:47:59 +01:00
package org.gcube.application.geoportal.common.model.document;
2023-04-18 10:33:22 +02:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
2021-11-24 14:47:59 +01:00
import org.bson.Document;
2022-02-14 12:23:13 +01:00
import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo;
2022-04-11 17:23:27 +02:00
import org.gcube.application.geoportal.common.model.document.identification.IdentificationReference;
2022-02-14 12:23:13 +01:00
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
2022-05-10 10:58:40 +02:00
import org.gcube.application.geoportal.common.model.document.relationships.Relationship;
2021-11-24 14:47:59 +01:00
2023-04-18 10:33:22 +02:00
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vdurmont.semver4j.Semver;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
2022-03-18 18:35:43 +01:00
2021-11-24 14:47:59 +01:00
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
2022-03-04 14:23:20 +01:00
public class Project {
2022-01-14 12:31:11 +01:00
2022-01-27 15:02:53 +01:00
public static final String ID="_id";
2022-02-18 18:12:02 +01:00
public static final String VERSION="_version";
public static final String INFO="_info";
public static final String PROFILE_ID="_profileID";
public static final String PROFILE_VERSION="_profileVersion";
public static final String LIFECYCLE_INFORMATION="_lifecycleInformation";
public static final String RELATIONSHIPS="_relationships";
2022-04-11 17:23:27 +02:00
public static final String IDENTIFICATION_REFERENCES="_identificationReferences";
2022-02-18 18:12:02 +01:00
public static final String THE_DOCUMENT="_theDocument";
2022-03-18 18:35:43 +01:00
public static final String LOCK="_lock";
2022-01-14 12:31:11 +01:00
2021-11-24 14:47:59 +01:00
// CORE METADATA
2022-02-23 17:13:22 +01:00
@JsonProperty(ID)
private String id;
@JsonProperty(VERSION)
2022-01-17 18:19:40 +01:00
private Semver version;
2021-11-24 14:47:59 +01:00
// Publication Info
2022-02-23 17:13:22 +01:00
@JsonProperty(INFO)
2021-11-24 14:47:59 +01:00
private PublicationInfo info;
2022-03-04 14:23:20 +01:00
// UseCaseDescriptor reference
2022-02-23 17:13:22 +01:00
@JsonProperty(PROFILE_ID)
2021-11-24 14:47:59 +01:00
private String profileID;
2022-02-23 17:13:22 +01:00
@JsonProperty(PROFILE_VERSION)
2022-01-17 18:19:40 +01:00
private Semver profileVersion;
2021-11-24 14:47:59 +01:00
2022-02-23 17:13:22 +01:00
@JsonProperty(LIFECYCLE_INFORMATION)
2021-11-24 14:47:59 +01:00
private LifecycleInformation lifecycleInformation;
2022-02-23 17:13:22 +01:00
@JsonProperty(RELATIONSHIPS)
2022-04-11 17:23:27 +02:00
private List<Relationship> relationships;
2021-11-24 14:47:59 +01:00
2022-04-11 17:23:27 +02:00
@JsonProperty(IDENTIFICATION_REFERENCES)
private List<IdentificationReference> identificationReferences;
2021-11-24 14:47:59 +01:00
2022-02-23 17:13:22 +01:00
@JsonProperty(THE_DOCUMENT)
2021-11-24 14:47:59 +01:00
private Document theDocument;
2022-03-18 18:35:43 +01:00
@JsonProperty(LOCK)
private Lock lock;
/**
* Similar to equals but without checking following fields
*
* lock
* @param o
* @return
*/
public boolean isEquivalent(Object o) {
if (this == o) return true;
if (!(o instanceof Project)) return false;
Project project = (Project) o;
2022-04-11 17:23:27 +02:00
return Objects.equals(getId(), project.getId()) && Objects.equals(getVersion(), project.getVersion()) && Objects.equals(getInfo(), project.getInfo()) && Objects.equals(getProfileID(), project.getProfileID()) && Objects.equals(getProfileVersion(), project.getProfileVersion()) && Objects.equals(getLifecycleInformation(), project.getLifecycleInformation()) && Objects.equals(getIdentificationReferences(), project.getIdentificationReferences()) && Objects.equals(getRelationships(), project.getRelationships()) && Objects.equals(getTheDocument(), project.getTheDocument());
2022-03-18 18:35:43 +01:00
}
2022-04-11 17:23:27 +02:00
@JsonIgnore
public List<IdentificationReference> getIdentificationReferenceByType(String type){
if(identificationReferences==null) return Collections.emptyList();
else return identificationReferences.stream()
.filter(item -> item.getType().equals(type)).collect(Collectors.toList());
};
2022-05-10 10:58:40 +02:00
@JsonIgnore
public List<Relationship> getRelationshipsByName(String relation){
if(relationships==null)return Collections.emptyList();
else return relationships.stream().filter(relationship -> relationship.
getRelationshipName().equals(relation)).collect(Collectors.toList());
};
@JsonIgnore
public Project addRelation(Relationship rel){
if(relationships==null) relationships = new ArrayList<>();
relationships.add(rel);
return this;
}
2021-11-24 14:47:59 +01:00
}