/
CseCracCreationContext.java
162 lines (137 loc) · 7.03 KB
/
CseCracCreationContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.openrao.data.craccreation.creator.cse;
import com.powsybl.openrao.data.cracapi.Crac;
import com.powsybl.openrao.data.craccreation.creator.api.CracCreationReport;
import com.powsybl.openrao.data.craccreation.creator.api.ElementaryCreationContext;
import com.powsybl.openrao.data.craccreation.creator.api.stdcreationcontext.BranchCnecCreationContext;
import com.powsybl.openrao.data.craccreation.creator.api.stdcreationcontext.RemedialActionCreationContext;
import com.powsybl.openrao.data.craccreation.creator.api.stdcreationcontext.UcteCracCreationContext;
import com.powsybl.openrao.data.craccreation.creator.cse.criticalbranch.CseCriticalBranchCreationContext;
import com.powsybl.openrao.data.craccreation.creator.cse.outage.CseOutageCreationContext;
import com.powsybl.openrao.data.craccreation.creator.cse.remedialaction.CseRemedialActionCreationContext;
import java.time.OffsetDateTime;
import java.util.*;
/**
* @author Alexandre Montigny {@literal <alexandre.montigny at rte-france.com>}
*/
public class CseCracCreationContext implements UcteCracCreationContext {
private Crac crac;
private boolean isCreationSuccessful;
private CracCreationReport creationReport;
private Map<String, CseCriticalBranchCreationContext> criticalBranchCreationContexts = new HashMap<>();
private Map<String, CseCriticalBranchCreationContext> monitoredElementCreationContexts = new HashMap<>();
private Map<String, CseOutageCreationContext> outageCreationContexts = new HashMap<>();
private Map<String, CseRemedialActionCreationContext> remedialActionCreationContexts = new HashMap<>();
private final OffsetDateTime timestamp;
private final String networkName;
public CseCracCreationContext(Crac crac, OffsetDateTime timestamp, String networkName) {
this.crac = crac;
this.timestamp = timestamp;
this.networkName = networkName;
creationReport = new CracCreationReport();
}
protected CseCracCreationContext(CseCracCreationContext toCopy) {
this.crac = toCopy.crac;
this.isCreationSuccessful = toCopy.isCreationSuccessful;
this.creationReport = new CracCreationReport(toCopy.creationReport);
this.criticalBranchCreationContexts = new HashMap<>(toCopy.criticalBranchCreationContexts);
this.monitoredElementCreationContexts = new HashMap<>(toCopy.monitoredElementCreationContexts);
this.outageCreationContexts = new HashMap<>(toCopy.outageCreationContexts);
this.remedialActionCreationContexts = new HashMap<>(toCopy.remedialActionCreationContexts);
this.timestamp = toCopy.timestamp;
this.networkName = toCopy.networkName;
}
@Override
public List<? extends BranchCnecCreationContext> getBranchCnecCreationContexts() {
ArrayList<CseCriticalBranchCreationContext> list = new ArrayList<>(criticalBranchCreationContexts.values());
list.addAll(monitoredElementCreationContexts.values());
return list;
}
@Override
public List<? extends RemedialActionCreationContext> getRemedialActionCreationContexts() {
return new ArrayList<>(remedialActionCreationContexts.values());
}
@Override
public OffsetDateTime getTimeStamp() {
return timestamp;
}
@Override
public String getNetworkName() {
return networkName;
}
@Override
public boolean isCreationSuccessful() {
return isCreationSuccessful;
}
@Override
public Crac getCrac() {
return crac;
}
void buildCreationReport() {
addToReport(outageCreationContexts.values(), "Outage");
addToReport(criticalBranchCreationContexts.values(), "Critical branch");
addToReport(monitoredElementCreationContexts.values(), "Monitored element");
addToReport(remedialActionCreationContexts.values(), "Remedial action");
}
private void addToReport(Collection<? extends ElementaryCreationContext> contexts, String nativeTypeIdentifier) {
contexts.stream().filter(ElementaryCreationContext::isAltered)
.sorted(Comparator.comparing(ElementaryCreationContext::getNativeId))
.forEach(context ->
creationReport.altered(String.format("%s \"%s\" was modified: %s. ", nativeTypeIdentifier, context.getNativeId(), context.getImportStatusDetail()))
);
contexts.stream().filter(context -> !context.isImported())
.sorted(Comparator.comparing(ElementaryCreationContext::getNativeId))
.forEach(context ->
creationReport.removed(String.format("%s \"%s\" was not imported: %s. %s.", nativeTypeIdentifier, context.getNativeId(), context.getImportStatus(), context.getImportStatusDetail()))
);
}
@Override
public CracCreationReport getCreationReport() {
return creationReport;
}
public void addCriticalBranchCreationContext(CseCriticalBranchCreationContext cseCriticalBranchCreationContext) {
this.criticalBranchCreationContexts.put(cseCriticalBranchCreationContext.getNativeId(), cseCriticalBranchCreationContext);
}
public void addMonitoredElementCreationContext(CseCriticalBranchCreationContext cseCriticalBranchCreationContext) {
this.monitoredElementCreationContexts.put(cseCriticalBranchCreationContext.getNativeId(), cseCriticalBranchCreationContext);
}
@Override
public BranchCnecCreationContext getBranchCnecCreationContext(String nativeCnecId) {
if (criticalBranchCreationContexts.containsKey(nativeCnecId)) {
return criticalBranchCreationContexts.get(nativeCnecId);
} else {
return monitoredElementCreationContexts.get(nativeCnecId);
}
}
public CseOutageCreationContext getOutageCreationContext(String outageName) {
return outageCreationContexts.get(outageName);
}
public List<CseOutageCreationContext> getOutageCreationContexts() {
return new ArrayList<>(outageCreationContexts.values());
}
public void addOutageCreationContext(CseOutageCreationContext cseOutageCreationContext) {
this.outageCreationContexts.put(cseOutageCreationContext.getNativeId(), cseOutageCreationContext);
}
@Override
public RemedialActionCreationContext getRemedialActionCreationContext(String raName) {
return remedialActionCreationContexts.get(raName);
}
public void addRemedialActionCreationContext(CseRemedialActionCreationContext remedialActionCreationContext) {
this.remedialActionCreationContexts.put(remedialActionCreationContext.getNativeId(), remedialActionCreationContext);
}
CseCracCreationContext creationFailure() {
this.isCreationSuccessful = false;
this.crac = null;
return this;
}
CseCracCreationContext creationSuccess(Crac crac) {
this.isCreationSuccessful = true;
this.crac = crac;
return this;
}
}