InventoryExtraDTO.java
/*
* Copyright 2023 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gringlobal.api.model;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import org.genesys.blocks.util.JsonClassNameWriter;
import org.gringlobal.custom.json.CustomTypeIdResolver;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "_class")
@JsonTypeIdResolver(InventoryExtraDTO.InventoryExtraDTOTypeIdResolver.class)
/* @formatter:off */
@JsonAppend(props = {
@JsonAppend.Prop(name = "_class", value = JsonClassNameWriter.class, type = String.class),
// @JsonAppend.Prop(name = "_permissions", value = GGCEPermissionsWriter.class, type = Permissions.class)
})
/* @formatter:on */
public abstract class InventoryExtraDTO extends CooperatorOwnedDTO {
private InventoryInfo inventory;
private String extraType;
@Data
@EqualsAndHashCode(callSuper = true)
public static class TissueCultureExtraDTO extends InventoryExtraDTO {
private MaterielInfo medium;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class SeedInventoryExtraDTO extends InventoryExtraDTO {
private InventoryViabilityInfo lastViability;
@Min(0) @Max(100)
private Double initialViability;
private Date initialViabilityDate;
private String initialViabilityDateCode;
@Min(0) @Max(100)
private Double lastViabilityResult;
private Date lastViabilityDate;
private String lastViabilityDateCode;
@Min(0) @Max(100)
private Float moistureContent;
private Date moistureContentDate;
private String moistureContentDateCode;
}
public static class InventoryExtraDTOTypeIdResolver extends CustomTypeIdResolver implements TypeIdResolver {
@Override
protected Map<String, Class<?>> initClassesMap() {
Map<String, Class<?>> classes = new HashMap<>();
classes.put(SeedInventoryExtraDTO.class.getSimpleName(), SeedInventoryExtraDTO.class);
classes.put(TissueCultureExtraDTO.class.getSimpleName(), TissueCultureExtraDTO.class);
return classes;
}
}
}