package org.gcube.application.geoportal.common.model.profile; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.bind.annotation.XmlRootElement; import com.fasterxml.jackson.annotation.JsonProperty; import com.vdurmont.semver4j.Semver; import lombok.Data; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.XSlf4j; import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo; @Data @NoArgsConstructor @XmlRootElement @Slf4j public class Profile{ public static final String ID="_id"; public static final String VERSION="_version"; public static final String NAME="_name"; public static final String DESCRIPTION="_description"; public static final String CREATION_INFO="_creationInfo"; public static final String SCHEMA="_schema"; public static final String HANDLERS="_handlers"; public static final String DATA_ACCESS_POLICIES="_dataAccessPolicies"; @JsonProperty(ID) private String id; @JsonProperty(VERSION) private Semver version; @JsonProperty(NAME) private String name; @JsonProperty(DESCRIPTION) private String description; @JsonProperty(CREATION_INFO) private AccountingInfo creationInfo; @JsonProperty(SCHEMA) private Field schema; @JsonProperty(HANDLERS) private List handlers; @JsonProperty(DATA_ACCESS_POLICIES) private List dataAccessPolicies; /** * Returns map Type -> Handler Declaration * @return */ public Map> getHandlersMapByType(){ HashMap> toReturn=new HashMap<>(); handlers.forEach(h->{ try { if(!toReturn.containsKey(h.getType())) toReturn.put(h.getType(),new ArrayList<>()); toReturn.get(h.getType()).add(h); }catch (Throwable t){log.error("Invalid profile : unable to get Handler Map by Type with {} in profile [ID {}]",h,this.getId(),t);} }); return toReturn; } /** * Returns map Type -> Handler Declaration * @return */ public Map> getHandlersMapByID(){ HashMap> toReturn=new HashMap<>(); handlers.forEach(h->{ try { if (!toReturn.containsKey(h.getId())) toReturn.put(h.getId(), new ArrayList<>()); toReturn.get(h.getId()).add(h); }catch (Throwable t){ log.error("Invalid profile : unable to get Handler Map by ID with {} in profile [ID {}]",h,this.getId(),t);} }); return toReturn; } }