use of org.jboss.resteasy.plugins.providers.multipart.InputPart in project keycloak by keycloak.
the class RealmLocalizationResource method createOrUpdateRealmLocalizationTextsFromFile.
/**
* Import localization from uploaded JSON file
*/
@POST
@Path("{locale}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void createOrUpdateRealmLocalizationTextsFromFile(@PathParam("locale") String locale, MultipartFormDataInput input) {
this.auth.realm().requireManageRealm();
Map<String, List<InputPart>> formDataMap = input.getFormDataMap();
if (!formDataMap.containsKey("file")) {
throw new BadRequestException();
}
InputPart file = formDataMap.get("file").get(0);
try (InputStream inputStream = file.getBody(InputStream.class, null)) {
TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {
};
Map<String, String> rep = JsonSerialization.readValue(inputStream, typeRef);
realm.createOrUpdateRealmLocalizationTexts(locale, rep);
} catch (IOException e) {
throw new BadRequestException("Could not read file.");
}
}
Aggregations