Skip to content

Commit

Permalink
MOSIP-25202 - fix sonar reliability issues
Browse files Browse the repository at this point in the history
Signed-off-by: Youssef MAHTAT <[email protected]>
  • Loading branch information
ymahtat-dev committed Nov 19, 2024
1 parent dec5813 commit 35faeb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
27 changes: 15 additions & 12 deletions src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,11 @@ private void setTemplateAttributes(String jsonString, Map<String, Object> attrib
* @throws Exception
*/
private String getPassword(org.json.JSONObject jsonObject) throws ApisResourceAccessException, IOException {

String[] attributes = env.getProperty(UINCARDPASSWORD).split("\\|");
String propertyValue = Objects.requireNonNull(
env.getProperty(UINCARDPASSWORD),
"Environment property '" + UINCARDPASSWORD + "' is missing."
);
String[] attributes = propertyValue.split("\\|");
List<String> list = new ArrayList<>(Arrays.asList(attributes));
Iterator<String> it = list.iterator();
String uinCardPd = "";
Expand All @@ -660,16 +663,16 @@ private String getPassword(org.json.JSONObject jsonObject) throws ApisResourceAc
} catch (Exception e) {
obj = object;
}
}
if (obj instanceof JSONArray) {
JsonValue[] jsonValues = JsonUtil.mapJsonNodeToJavaObject(JsonValue.class, (JSONArray) obj);
uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute(getParameter(jsonValues, templateLang)));

} else if (object instanceof org.json.simple.JSONObject) {
org.json.simple.JSONObject json = (org.json.simple.JSONObject) object;
uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute((String) json.get(VALUE)));
} else {
uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute(object.toString()));
if (obj instanceof JSONArray) {
JsonValue[] jsonValues = JsonUtil.mapJsonNodeToJavaObject(JsonValue.class, (JSONArray) obj);
uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute(getParameter(jsonValues, templateLang)));

} else if (object instanceof org.json.simple.JSONObject) {
org.json.simple.JSONObject json = (org.json.simple.JSONObject) object;
uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute((String) json.get(VALUE)));
} else {
uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute(object.toString()));
}
}
}
return uinCardPd;
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/io/mosip/print/util/RestApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.net.URI;
import java.util.Iterator;
import java.util.List;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -117,8 +119,12 @@ private HttpEntity<Object> setRequestHeader(Object requestType, MediaType mediaT
Iterator<String> iterator = httpHeader.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
if (!(headers.containsKey("Content-Type") && key.equals("Content-Type")))
headers.add(key, httpHeader.get(key).get(0));
if (!(headers.containsKey("Content-Type") && key.equals("Content-Type"))) {
List<String> values = httpHeader.get(key);
if (values != null && !values.isEmpty()) {
headers.add(key, values.getFirst());
}
}
}
return new HttpEntity<Object>(httpEntity.getBody(), headers);
} catch (ClassCastException | NullPointerException e) {
Expand Down

0 comments on commit 35faeb8

Please sign in to comment.