Skip to content

Commit

Permalink
Introducing method returning unique fields in Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-peter committed Feb 9, 2024
1 parent 3b746a0 commit b6d0f30
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 64 deletions.
9 changes: 9 additions & 0 deletions src/main/java/edu/ie3/datamodel/io/factory/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ private void isSupportedClass(Class<?> desiredClass) {
.collect(Collectors.joining("\n - ")));
}

/**
* Returns a list of sets of field names that are required to be unique throughout the whole
* dataset. For each set, the combination of all members of the set must be unique. This means
* that individual members of the set are not required to be unique, but only their combination.
* Sets with only a single member are exempt here; the single field must be unique throughout the
* dataset.
*/
public abstract List<Set<String>> getUniqueFields();

/**
* Returns list of sets of attribute names that the entity requires to be built. At least one of
* these sets needs to be delivered for entity creation to be successful.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* © 2024. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.io.factory;

import edu.ie3.datamodel.models.Entity;
import java.util.List;
import java.util.Set;

/**
* Universal factory class for creating entities with unique fields uuid and id.
*
* @param <T> Type of entity that this factory can create. Can be a subclass of the entities that
* this factory creates.
* @param <D> Type of data class that is required for entity creation
*/
public abstract class UniqueEntityFactory<T extends Entity, D extends EntityData>
extends EntityFactory<T, D> {

protected static final String UUID = "uuid";

protected static final String ID = "id";

public UniqueEntityFactory(Class<? extends T>... allowedClasses) {

Check warning on line 26 in src/main/java/edu/ie3/datamodel/io/factory/UniqueEntityFactory.java

View check run for this annotation

SonarQubeGithubPRChecks / PowerSystemDataModel Sonarqube Results

src/main/java/edu/ie3/datamodel/io/factory/UniqueEntityFactory.java#L26

Change the visibility of this constructor to "protected".
super(allowedClasses);
}

@Override
public List<Set<String>> getUniqueFields() {
return List.of(newSet(UUID), newSet(ID));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
package edu.ie3.datamodel.io.factory.input;

import edu.ie3.datamodel.io.factory.EntityFactory;
import edu.ie3.datamodel.io.factory.UniqueEntityFactory;
import edu.ie3.datamodel.models.OperationTime;
import edu.ie3.datamodel.models.input.AssetInput;
import edu.ie3.datamodel.models.input.OperatorInput;
Expand All @@ -22,12 +22,10 @@
* @since 19.02.20
*/
public abstract class AssetInputEntityFactory<T extends AssetInput, D extends AssetInputEntityData>
extends EntityFactory<T, D> {
extends UniqueEntityFactory<T, D> {

private static final String UUID = "uuid";
private static final String OPERATES_FROM = "operatesFrom";
private static final String OPERATES_UNTIL = "operatesUntil";
private static final String ID = "id";

protected AssetInputEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@
package edu.ie3.datamodel.io.factory.input;

import edu.ie3.datamodel.io.factory.EntityData;
import edu.ie3.datamodel.io.factory.EntityFactory;
import edu.ie3.datamodel.io.factory.UniqueEntityFactory;
import edu.ie3.datamodel.models.input.OperatorInput;
import java.util.Collections;
import java.util.List;
import java.util.Set;

public class OperatorInputFactory extends EntityFactory<OperatorInput, EntityData> {

private static final String ENTITY_UUID = "uuid";
private static final String ENTITY_ID = "id";
public class OperatorInputFactory extends UniqueEntityFactory<OperatorInput, EntityData> {

public OperatorInputFactory() {
super(OperatorInput.class);
}

@Override
protected List<Set<String>> getFields(Class<?> entityClass) {
Set<String> constructorParams = newSet(ENTITY_UUID, ENTITY_ID);
Set<String> constructorParams = newSet(UUID, ID);
return Collections.singletonList(constructorParams);
}

@Override
protected OperatorInput buildModel(EntityData data) {
return new OperatorInput(data.getUUID(ENTITY_UUID), data.getField(ENTITY_ID));
return new OperatorInput(data.getUUID(UUID), data.getField(ID));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ protected List<Set<String>> getFields(Class<?> entityClass) {
return Collections.singletonList(constructorParamsMin);
}

@Override
public List<Set<String>> getUniqueFields() {
return List.of(newSet(UUID));
}

/**
* Returns fields other than the required fields of {@link GraphicInput} that have to be present.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import edu.ie3.datamodel.models.result.ResultEntity;
import edu.ie3.util.TimeUtil;
import java.time.ZoneId;
import java.util.List;
import java.util.Locale;
import java.util.Set;

/**
* Internal API for building {@link ResultEntity}s. This additional abstraction layer is necessary
Expand All @@ -35,4 +37,9 @@ protected ResultEntityFactory(String dtfPattern, Class<? extends T>... allowedCl
super(allowedClasses);
timeUtil = new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern);
}

@Override
public List<Set<String>> getUniqueFields() {
return List.of(newSet(TIME, INPUT_MODEL));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import edu.ie3.datamodel.io.factory.Factory;
import edu.ie3.datamodel.io.factory.SimpleFactoryData;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.tuple.Pair;
import org.locationtech.jts.geom.Point;

Expand All @@ -28,4 +30,9 @@ protected IdCoordinateFactory() {

/** @return the field id for the coordinate longitude */
public abstract String getLonField();

@Override
public List<Set<String>> getUniqueFields() {
return List.of(newSet(getIdField()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

public class TimeBasedSimpleValueFactory<V extends Value>
extends TimeBasedValueFactory<SimpleTimeBasedValueData<V>, V> {
private static final String UUID = "uuid";
private static final String TIME = "time";
/* Energy price */
private static final String PRICE = "price";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import edu.ie3.datamodel.io.factory.Factory;
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
import edu.ie3.datamodel.models.value.Value;
import java.util.List;
import java.util.Set;

/**
* Abstract class that is able to build {@link TimeBasedValue}s from "flat" information
Expand All @@ -17,7 +19,15 @@
*/
public abstract class TimeBasedValueFactory<D extends TimeBasedValueData<V>, V extends Value>
extends Factory<V, D, TimeBasedValue<V>> {

protected static final String UUID = "uuid";

protected TimeBasedValueFactory(Class<? extends V>... valueClasses) {
super(valueClasses);
}

@Override
public List<Set<String>> getUniqueFields() {
return List.of(newSet(UUID));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
public abstract class TimeBasedWeatherValueFactory
extends TimeBasedValueFactory<TimeBasedWeatherValueData, WeatherValue> {
protected static final String UUID = "uuid";
protected static final String TIME = "time";
protected static final String COORDINATE_ID = "coordinateId";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ protected TimeSeriesMappingSource.MappingEntry buildModel(EntityData data) {
UUID timeSeries = data.getUUID(TIME_SERIES);
return new TimeSeriesMappingSource.MappingEntry(uuid, participant, timeSeries);
}

@Override
public List<Set<String>> getUniqueFields() {
return List.of(newSet(UUID));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected IndividualTimeSeriesMetaInformation buildModel(EntityData data) {
ColumnScheme columnScheme = ColumnScheme.parse(data.getField(COLUMN_SCHEME)).orElseThrow();
return new IndividualTimeSeriesMetaInformation(timeSeries, columnScheme);
}

@Override
public List<Set<String>> getUniqueFields() {
return List.of(newSet(TIME_SERIES));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package edu.ie3.datamodel.io.factory.typeinput;

import edu.ie3.datamodel.io.factory.EntityData;
import edu.ie3.datamodel.io.factory.EntityFactory;
import edu.ie3.datamodel.io.factory.UniqueEntityFactory;
import edu.ie3.datamodel.models.input.AssetTypeInput;

/**
Expand All @@ -18,10 +18,7 @@
* @since 11.02.20
*/
abstract class AssetTypeInputEntityFactory<T extends AssetTypeInput>
extends EntityFactory<T, EntityData> {

protected static final String ENTITY_UUID = "uuid";
protected static final String ENTITY_ID = "id";
extends UniqueEntityFactory<T, EntityData> {

protected AssetTypeInputEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public LineTypeInputFactory() {

@Override
protected List<Set<String>> getFields(Class<?> entityClass) {
Set<String> constructorParams = newSet(ENTITY_UUID, ENTITY_ID, B, G, R, X, I_MAX, V_RATED);
Set<String> constructorParams = newSet(UUID, ID, B, G, R, X, I_MAX, V_RATED);

return Collections.singletonList(constructorParams);
}

@Override
protected LineTypeInput buildModel(EntityData data) {
UUID uuid = data.getUUID(ENTITY_UUID);
String id = data.getField(ENTITY_ID);
UUID uuid = data.getUUID(UUID);
String id = data.getField(ID);
ComparableQuantity<SpecificConductance> b =
data.getQuantity(B, StandardUnits.SUSCEPTANCE_PER_LENGTH);
ComparableQuantity<SpecificConductance> g =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public SystemParticipantTypeInputFactory() {

@Override
protected List<Set<String>> getFields(Class<?> entityClass) {
Set<String> standardConstructorParams =
newSet(ENTITY_UUID, ENTITY_ID, CAP_EX, OP_EX, S_RATED, COS_PHI_RATED);
Set<String> standardConstructorParams = newSet(UUID, ID, CAP_EX, OP_EX, S_RATED, COS_PHI_RATED);

Set<String> constructorParameters = null;
if (entityClass.equals(EvTypeInput.class)) {
Expand Down Expand Up @@ -106,8 +105,8 @@ protected List<Set<String>> getFields(Class<?> entityClass) {

@Override
protected SystemParticipantTypeInput buildModel(EntityData data) {
UUID uuid = data.getUUID(ENTITY_UUID);
String id = data.getField(ENTITY_ID);
UUID uuid = data.getUUID(UUID);
String id = data.getField(ID);
ComparableQuantity<Currency> capEx = data.getQuantity(CAP_EX, StandardUnits.CAPEX);
ComparableQuantity<EnergyPrice> opEx = data.getQuantity(OP_EX, StandardUnits.ENERGY_PRICE);
ComparableQuantity<Power> sRated = data.getQuantity(S_RATED, StandardUnits.S_RATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,16 @@ public Transformer2WTypeInputFactory() {
protected List<Set<String>> getFields(Class<?> entityClass) {
Set<String> constructorParams =
newSet(
ENTITY_UUID,
ENTITY_ID,
R_SC,
X_SC,
S_RATED,
V_RATED_A,
V_RATED_B,
G_M,
B_M,
D_V,
D_PHI,
TAP_SIDE,
TAP_NEUTR,
TAP_MIN,
TAP_MAX);
UUID, ID, R_SC, X_SC, S_RATED, V_RATED_A, V_RATED_B, G_M, B_M, D_V, D_PHI, TAP_SIDE,
TAP_NEUTR, TAP_MIN, TAP_MAX);

return Collections.singletonList(constructorParams);
}

@Override
protected Transformer2WTypeInput buildModel(EntityData data) {
UUID uuid = data.getUUID(ENTITY_UUID);
String id = data.getField(ENTITY_ID);
UUID uuid = data.getUUID(UUID);
String id = data.getField(ID);
ComparableQuantity<ElectricResistance> rSc = data.getQuantity(R_SC, StandardUnits.RESISTANCE);
ComparableQuantity<ElectricResistance> xSc = data.getQuantity(X_SC, StandardUnits.REACTANCE);
ComparableQuantity<Power> sRated = data.getQuantity(S_RATED, StandardUnits.S_RATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,17 @@ public Transformer3WTypeInputFactory() {
protected List<Set<String>> getFields(Class<?> entityClass) {
Set<String> constructorParams =
newSet(
ENTITY_UUID,
ENTITY_ID,
S_RATED_A,
S_RATED_B,
S_RATED_C,
V_RATED_A,
V_RATED_B,
V_RATED_C,
R_SC_A,
R_SC_B,
R_SC_C,
X_SC_A,
X_SC_B,
X_SC_C,
G_M,
B_M,
D_V,
D_PHI,
TAP_NEUTR,
TAP_MIN,
UUID, ID, S_RATED_A, S_RATED_B, S_RATED_C, V_RATED_A, V_RATED_B, V_RATED_C, R_SC_A,
R_SC_B, R_SC_C, X_SC_A, X_SC_B, X_SC_C, G_M, B_M, D_V, D_PHI, TAP_NEUTR, TAP_MIN,
TAP_MAX);

return Collections.singletonList(constructorParams);
}

@Override
protected Transformer3WTypeInput buildModel(EntityData data) {
UUID uuid = data.getUUID(ENTITY_UUID);
String id = data.getField(ENTITY_ID);
UUID uuid = data.getUUID(UUID);
String id = data.getField(ID);
ComparableQuantity<Power> sRatedA = data.getQuantity(S_RATED_A, StandardUnits.S_RATED);
ComparableQuantity<Power> sRatedB = data.getQuantity(S_RATED_B, StandardUnits.S_RATED);
ComparableQuantity<Power> sRatedC = data.getQuantity(S_RATED_C, StandardUnits.S_RATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class FactoryTest extends Specification {
return null
}

@Override
List<Set<String>> getUniqueFields() {
return null
}

@Override
protected List<Set<String>> getFields(Class<?> entityClass) {
return [
Expand Down

0 comments on commit b6d0f30

Please sign in to comment.