This repository has been archived by the owner on May 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve security-analysis results (#199)
Improve security-analysis results
- Loading branch information
Showing
23 changed files
with
484 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
commons/src/main/java/eu/itesla_project/commons/json/JsonUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) 2017, 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 eu.itesla_project.commons.json; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.google.common.base.Strings; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author Mathieu Bague <[email protected]> | ||
*/ | ||
public final class JsonUtil { | ||
|
||
private JsonUtil() { | ||
} | ||
|
||
public static void writeOptionalStringField(JsonGenerator jsonGenerator, String fieldName, String value) throws IOException { | ||
Objects.requireNonNull(jsonGenerator); | ||
Objects.requireNonNull(fieldName); | ||
|
||
if (!Strings.isNullOrEmpty(value)) { | ||
jsonGenerator.writeStringField(fieldName, value); | ||
} | ||
} | ||
|
||
public static void writeOptionalEnumField(JsonGenerator jsonGenerator, String fieldName, Enum<?> value) throws IOException { | ||
Objects.requireNonNull(jsonGenerator); | ||
Objects.requireNonNull(fieldName); | ||
|
||
if (value != null) { | ||
jsonGenerator.writeStringField(fieldName, value.name()); | ||
} | ||
} | ||
|
||
public static void writeOptionalFloatField(JsonGenerator jsonGenerator, String fieldName, float value) throws IOException { | ||
Objects.requireNonNull(jsonGenerator); | ||
Objects.requireNonNull(fieldName); | ||
|
||
if (!Float.isNaN(value)) { | ||
jsonGenerator.writeNumberField(fieldName, value); | ||
} | ||
} | ||
|
||
public static void writeOptionalIntegerField(JsonGenerator jsonGenerator, String fieldName, int value) throws IOException { | ||
Objects.requireNonNull(jsonGenerator); | ||
Objects.requireNonNull(fieldName); | ||
|
||
if (value != Integer.MAX_VALUE) { | ||
jsonGenerator.writeNumberField(fieldName, value); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...cy-api/src/main/java/eu/itesla_project/contingency/json/ContingencyElementSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) 2017, 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 eu.itesla_project.contingency.json; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
import eu.itesla_project.commons.json.JsonUtil; | ||
import eu.itesla_project.contingency.BranchContingency; | ||
import eu.itesla_project.contingency.ContingencyElement; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* @author Mathieu Bague <[email protected]> | ||
*/ | ||
public class ContingencyElementSerializer extends StdSerializer<ContingencyElement> { | ||
|
||
public ContingencyElementSerializer() { | ||
super(ContingencyElement.class); | ||
} | ||
|
||
@Override | ||
public void serialize(ContingencyElement contingencyElement, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | ||
jsonGenerator.writeStartObject(); | ||
jsonGenerator.writeStringField("id", contingencyElement.getId()); | ||
jsonGenerator.writeStringField("type", contingencyElement.getType().name()); | ||
if (contingencyElement instanceof BranchContingency) { | ||
BranchContingency branchContingencyElement = (BranchContingency) contingencyElement; | ||
JsonUtil.writeOptionalStringField(jsonGenerator, "voltageLevelId", branchContingencyElement.getVoltageLevelId()); | ||
} | ||
jsonGenerator.writeEndObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.