* All existing state data are removed.
* @return
*/
- public List<StateData> setStateDataOnly(List<State> states){
+ public List<StateData> setStateDataOnly(List<? extends DefinedTermBase<?>> states){
List<StateData> stateDataList = new ArrayList<>(getStateData());
for (StateData stateData : stateDataList) {
removeStateData(stateData);
}
- for (State state : states) {
+ for (DefinedTermBase<?> state : states) {
addStateData(state);
}
return this.stateData;
DefinedTermBase.cacher = cacher;
}
+ /**
+ * Returns the term with the given {@link UUID} and the exact given {@link Class} from
+ * the cache or loads it from the database. If the term exists but has a
+ * different class <code>null</code> is returned. This is also the case for
+ * if the class is assignable from the given class.
+ *
+ * @see #getTermByUUID(UUID, Class)
+ */
public static <T extends DefinedTermBase> T getTermByClassAndUUID(Class<T> clazz, UUID uuid) {
if(cacher != null) {
CdmBase cdmBase = HibernateProxyHelper.deproxy(getCacher().load(uuid));
}
return null;
}
+
+ /**
+ * Returns the term from the cache or loads it from the database
+ * and casts it to the given class.
+ * In contrary to {@link #getTermByClassAndUUID(Class, UUID)} it
+ * throws an exception if the term can not be casted.
+ */
+ public static <T extends DefinedTermBase> T getTermByUUID(UUID uuid, Class<T> clazz) {
+ if(cacher != null) {
+ return HibernateProxyHelper.deproxy(getCacher().load(uuid), clazz);
+ }
+ return null;
+ }
}
\ No newline at end of file
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
import eu.etaxonomy.cdm.model.description.QuantitativeData;
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
-import eu.etaxonomy.cdm.model.description.State;
import eu.etaxonomy.cdm.model.description.StateData;
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
continue;
}
List<DescriptionElementBase> equalUuidsElements = descriptionElements.stream().filter( e -> e.getUuid().equals(descElementUuid)).collect(Collectors.toList());
- eu.etaxonomy.cdm.model.description.Feature feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Feature.class, descElement.getFeatureUuid());
- if (feature == null){
- feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, descElement.getFeatureUuid());
- }
+ Feature feature = DefinedTermBase.getTermByUUID(descElement.getFeatureUuid(), Feature.class);
+
if (equalUuidsElements.size() == 0){
if (descElement instanceof CategoricalDataDto){
List<StateDataDto> stateDtos = ((CategoricalDataDto)descElement).getStates();
for (StateDataDto dataDto: stateDtos){
//create new statedata
- //FIXME 10196
- State newState = DefinedTermBase.getTermByClassAndUUID(State.class, dataDto.getState().getUuid());
+ //FIXME 10196 fixed
+ DefinedTermBase<?> newState = DefinedTermBase.getTermByUUID(dataDto.getState().getUuid(), DefinedTermBase.class);
StateData newStateData = StateData.NewInstance(newState);
elementBase.addStateData(newStateData);
}
import eu.etaxonomy.cdm.model.description.PolytomousKey;
import eu.etaxonomy.cdm.model.description.QuantitativeData;
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
-import eu.etaxonomy.cdm.model.description.State;
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
for (DescriptionElementDto elementDto: elementDtos){
if (elementDto instanceof CategoricalDataDto){
- eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
+ Feature feature = DefinedTermBase.getTermByUUID(elementDto.getFeatureUuid(), Feature.class);
CategoricalData data = CategoricalData.NewInstance(feature);
for (StateDataDto stateDto:((CategoricalDataDto) elementDto).getStates()){
- //FIXME 10196
- State state = DefinedTermBase.getTermByClassAndUUID(State.class, stateDto.getState().getUuid());
+ //FIXME 10196 fixed?
+ DefinedTermBase<?> state = DefinedTermBase.getTermByUUID(stateDto.getState().getUuid(), DefinedTermBase.class);
data.addStateData(state);
specimenDescription.addElement(data);
}
}
if (elementDto instanceof QuantitativeDataDto){
- eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
+ Feature feature = DefinedTermBase.getTermByUUID(elementDto.getFeatureUuid(), Feature.class);
QuantitativeData data = QuantitativeData.NewInstance(feature);
if (((QuantitativeDataDto) elementDto).getMeasurementUnit() != null){
MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) elementDto).getMeasurementUnit().getUuid());
List<DescriptionElementDto> elementDtos = descriptionDto.getElements();
for (DescriptionElementDto elementDto: elementDtos){
if (elementDto instanceof CategoricalDataDto){
- eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
+ Feature feature = DefinedTermBase.getTermByUUID(elementDto.getFeatureUuid(), Feature.class);
List<DescriptionElementBase> uniqueElementList = specimenDescription.getElements().stream().filter(element -> element.getUuid().equals(elementDto.getElementUuid())).collect(Collectors.toList());
- List<State> allStates = new ArrayList<>();
+ List<DefinedTermBase<?>> allStates = new ArrayList<>();
CategoricalData element = null;
if (uniqueElementList.size() == 1){
element = HibernateProxyHelper.deproxy(uniqueElementList.get(0), CategoricalData.class);
element = CategoricalData.NewInstance(feature);
}
for (StateDataDto stateDto:((CategoricalDataDto) elementDto).getStates()){
- //FIXME 10196
- State state = DefinedTermBase.getTermByClassAndUUID(State.class, stateDto.getState().getUuid());
+ //FIXME 10196 fixed?
+ DefinedTermBase<?> state = DefinedTermBase.getTermByUUID(stateDto.getState().getUuid(), DefinedTermBase.class);
allStates.add(state);
}
element.setStateDataOnly(allStates);
}
if (elementDto instanceof QuantitativeDataDto){
- eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
+ Feature feature = DefinedTermBase.getTermByUUID(elementDto.getFeatureUuid(), Feature.class);
QuantitativeData data = QuantitativeData.NewInstance(feature);
if (((QuantitativeDataDto) elementDto).getMeasurementUnit() != null){
MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) elementDto).getMeasurementUnit().getUuid());
import org.apache.commons.lang3.StringUtils;
import eu.etaxonomy.cdm.model.description.CategoricalData;
-import eu.etaxonomy.cdm.model.description.Character;
import eu.etaxonomy.cdm.model.description.DescriptionBase;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.Feature;
}
}
}else{
- Feature feature = DefinedTermBase.getTermByClassAndUUID(Feature.class, featureUuid);
- if (feature == null){
- feature = DefinedTermBase.getTermByClassAndUUID(Character.class, featureUuid);
- }
+ Feature feature = DefinedTermBase.getTermByUUID(featureUuid, Feature.class);
categoricalData = new CategoricalDataDto(FeatureDto.fromFeature(feature));
categoricalData.setStateDataOnly(states);
}
}
QuantitativeDataDto quantitativeData = null;
if (descriptionElementBase == null){
- Feature feature = DefinedTermBase.getTermByClassAndUUID(Feature.class, featureUuid);
- if (feature == null){
- feature = DefinedTermBase.getTermByClassAndUUID(Character.class, featureUuid);
- }
+ Feature feature = DefinedTermBase.getTermByUUID(featureUuid, Feature.class);
quantitativeData = new QuantitativeDataDto(FeatureDto.fromFeature(feature));
}