Skip to content

Commit

Permalink
PageEvaluateMapping: cleanup + try-with-resource instead of closeQuietly
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Jun 9, 2020
1 parent 9aa7e79 commit 762e469
Showing 1 changed file with 25 additions and 37 deletions.
Expand Up @@ -7,6 +7,24 @@

package com.evolveum.midpoint.web.page.admin.configuration;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import com.evolveum.midpoint.gui.api.model.NonEmptyModel;
import com.evolveum.midpoint.gui.api.model.NonEmptyWrapperModel;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -25,27 +43,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingEvaluationRequestType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingEvaluationResponseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

/**
* @author mederly
*/
@PageDescriptor(url = "/admin/config/evaluateMapping", action = {
@AuthorizationAction(actionUri = PageAdminConfiguration.AUTH_CONFIGURATION_ALL,
label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL, description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION),
Expand Down Expand Up @@ -113,12 +111,7 @@ protected void onSubmit(AjaxRequestTarget target) {

final DropDownChoice<String> sampleChoice = new DropDownChoice<>(ID_MAPPING_SAMPLE,
Model.of(""),
new IModel<List<String>>() {
@Override
public List<String> getObject() {
return SAMPLES;
}
},
(IModel<List<String>>) () -> SAMPLES,
new StringResourceChoiceRenderer("PageEvaluateMapping.sample"));
sampleChoice.setNullValid(true);
sampleChoice.add(new OnChangeAjaxBehavior() {
Expand All @@ -135,17 +128,14 @@ protected void onUpdate(AjaxRequestTarget target) {
}

private String readResource(String name) {
InputStream is = PageEvaluateMapping.class.getResourceAsStream(name);
if (is != null) {
try {
try (InputStream is = PageEvaluateMapping.class.getResourceAsStream(name)) {
if (is != null) {
return IOUtils.toString(is, StandardCharsets.UTF_8);
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't read sample from resource {}", e, name);
} finally {
IOUtils.closeQuietly(is);
} else {
LOGGER.warn("Resource {} containing sample couldn't be found", name);
}
} else {
LOGGER.warn("Resource {} containing sample couldn't be found", name);
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't read sample from resource {}", e, name);
}
return null;
}
Expand Down Expand Up @@ -201,6 +191,4 @@ private void executeMappingPerformed(AjaxRequestTarget target) {
showResult(result);
target.add(this);
}


}

0 comments on commit 762e469

Please sign in to comment.