Skip to content

Commit 4194119

Browse files
authored
[ES-2627] Cache UISpec with TTL in esignet-signup (mosip#170)
* moved UI spec logic from init to separate method Signed-off-by: Md-Humair-KK <[email protected]> * resolved review comments Signed-off-by: Md-Humair-KK <[email protected]> * added fallback of default value to maxupload file size Signed-off-by: Md-Humair-KK <[email protected]> --------- Signed-off-by: Md-Humair-KK <[email protected]>
1 parent 0c336ff commit 4194119

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

mosip-identity-plugin/src/main/java/io/mosip/signup/plugin/mosipid/service/IdrepoProfileRegistryPluginImpl.java

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,30 +170,9 @@ public class IdrepoProfileRegistryPluginImpl implements ProfileRegistryPlugin {
170170
private String docTypesAndCategoryBaseUrl;
171171

172172

173-
private JsonNode uiSpec;
174-
175173
@PostConstruct
176174
public void init() {
177-
String responseJson = request(uiSpecUrl, HttpMethod.GET, null, new ParameterizedTypeReference<ResponseWrapper<JsonNode>>() {
178-
})
179-
.getResponse()
180-
.toString();
181-
Object schema = JsonPath.read(responseJson, schemaJsonpath);
182-
Object errors = readErrors(responseJson, errorsJsonpath);
183-
ObjectNode i18nValues = readI18nValues(responseJson);
184-
JsonNode allowedValues = readAllowedValues(responseJson);
185-
Object maxUploadFileSize = JsonPath.read(responseJson, maxUploadFileSizeJsonpath);
186175

187-
this.uiSpec = objectMapper.valueToTree(
188-
Map.ofEntries(
189-
Map.entry("schema", schema),
190-
Map.entry("errors", errors),
191-
Map.entry("i18nValues", i18nValues),
192-
Map.entry("language", Map.of("mandatory", mandatoryLanguages, "optional", optionalLanguages)),
193-
Map.entry("allowedValues", allowedValues),
194-
Map.entry("maxUploadFileSize", maxUploadFileSize)
195-
)
196-
);
197176
IIORegistry registry = IIORegistry.getDefaultInstance();
198177
registry.registerServiceProvider(new J2KImageReaderSpi());
199178
}
@@ -249,6 +228,22 @@ private Object readErrors(String responseJson, String jsonpath) {
249228
return errors;
250229
}
251230

231+
/**
232+
* Reads max upload file size from the UI-spec
233+
* @param responseJson the response json from ${mosip.signup.mosipid.get-ui-spec.endpoint}
234+
* @return maxUploadFileSize
235+
*/
236+
private Object readMaxUploadFileSize(String responseJson) {
237+
Object maxUploadFileSize;
238+
try {
239+
maxUploadFileSize = JsonPath.read(responseJson, maxUploadFileSizeJsonpath);
240+
} catch (PathNotFoundException e) {
241+
log.error("maxUploadFileSize not found in schema, setting to default");
242+
maxUploadFileSize = 5242880;
243+
}
244+
return maxUploadFileSize;
245+
}
246+
252247
/**
253248
* Generate combined JsonNode from List<JsonNode> dynamicFields and List<JsonNode> documentCategories
254249
* @return JsonNode containing the allowed values.
@@ -539,7 +534,26 @@ public boolean isMatch(JsonNode identity, JsonNode inputChallenge) {
539534

540535
@Override
541536
public JsonNode getUISpecification() {
542-
return this.uiSpec;
537+
String responseJson = request(uiSpecUrl, HttpMethod.GET, null, new ParameterizedTypeReference<ResponseWrapper<JsonNode>>() {
538+
})
539+
.getResponse()
540+
.toString();
541+
Object schema = JsonPath.read(responseJson, schemaJsonpath);
542+
Object errors = readErrors(responseJson, errorsJsonpath);
543+
ObjectNode i18nValues = readI18nValues(responseJson);
544+
JsonNode allowedValues = readAllowedValues(responseJson);
545+
Object maxUploadFileSize = readMaxUploadFileSize(responseJson);
546+
547+
return objectMapper.valueToTree(
548+
Map.ofEntries(
549+
Map.entry("schema", schema),
550+
Map.entry("errors", errors),
551+
Map.entry("i18nValues", i18nValues),
552+
Map.entry("language", Map.of("mandatory", mandatoryLanguages, "optional", optionalLanguages)),
553+
Map.entry("allowedValues", allowedValues),
554+
Map.entry("maxUploadFileSize", maxUploadFileSize)
555+
)
556+
);
543557
}
544558

545559
private SchemaResponse getSchemaJson(double version) throws ProfileException {

0 commit comments

Comments
 (0)