Skip to content

Commit

Permalink
Fixed RTF exports (MID-3932). Fixed failing model-test. Removed JXL f…
Browse files Browse the repository at this point in the history
…rom the list of report export types.
  • Loading branch information
mederly committed Dec 12, 2017
1 parent 4bafe93 commit b07b27e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 deletions.
Expand Up @@ -36,6 +36,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

Expand All @@ -45,6 +46,7 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.SubscriptionType;
import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
Expand Down Expand Up @@ -682,6 +684,14 @@ public List<T> getObject() {
};
}

@NotNull
public static <T extends Enum> IModel<List<T>> createReadonlyModelFromEnum(@NotNull Class<T> type, @NotNull Predicate<T> filter) {
return new ReadOnlyModel<>(() ->
Arrays.stream(type.getEnumConstants())
.filter(filter)
.collect(Collectors.toList()));
}

public static List<String> createTaskCategoryList() {
List<String> categories = new ArrayList<>();

Expand Down
Expand Up @@ -69,7 +69,7 @@ protected void initLayout() {
createStringResource("ObjectType.description"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
add(description);

IModel choices = WebComponentUtil.createReadonlyModelFromEnum(ExportType.class);
IModel choices = WebComponentUtil.createReadonlyModelFromEnum(ExportType.class, e -> e != ExportType.JXL);
IChoiceRenderer renderer = new EnumChoiceRenderer();
DropDownFormGroup exportType = new DropDownFormGroup(ID_EXPORT_TYPE, new PropertyModel<ExportType>(getModel(), ReportDto.F_EXPORT_TYPE), choices, renderer,
createStringResource("ReportType.export"), ID_LABEL_SIZE, ID_INPUT_SIZE, true);
Expand Down
Expand Up @@ -385,58 +385,70 @@ private String generateReport(ReportType reportType, JasperPrint jasperPrint) th
JasperExportManager.exportReportToHtmlFile(jasperPrint, destinationFileName);
break;
case CSV:
JRCsvExporter csvExporter = new JRCsvExporter();
csvExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
csvExporter.setExporterOutput(new SimpleWriterExporterOutput(destinationFileName));
csvExporter.exportReport();
break;
case RTF:
case XLS:
case ODT:
case ODS:
case DOCX:
case XLSX:
case PPTX:

case JXL:
ExporterInput input = new SimpleExporterInput(jasperPrint);
ExporterOutput output = new SimpleOutputStreamExporterOutput(destinationFileName);

Exporter exporter = createExporter(reportType.getExport());
if (exporter == null) {
break;
Exporter exporter = createExporter(reportType.getExport(), jasperPrint, destinationFileName);
if (exporter != null) {
exporter.exportReport();
}
exporter.setExporterInput(input);
exporter.setExporterOutput(output);
exporter.exportReport();
break;
default:
break;
}
return destinationFileName;
}

private Exporter createExporter(ExportType type) {
private Exporter createExporter(ExportType type, JasperPrint jasperPrint, String destinationFileName) {
Exporter exporter;
boolean writerOutput;
switch (type) {
case CSV:
return new JRCsvExporter();
writerOutput = true;
exporter = new JRCsvExporter();
break;
case RTF:
return new JRRtfExporter();
writerOutput = true;
exporter = new JRRtfExporter();
break;
case XLS:
return new JRXlsExporter();
writerOutput = false;
exporter = new JRXlsExporter();
break;
case ODT:
return new JROdtExporter();
writerOutput = false;
exporter = new JROdtExporter();
break;
case ODS:
return new JROdsExporter();
writerOutput = false;
exporter = new JROdsExporter();
break;
case DOCX:
return new JRDocxExporter();
writerOutput = false;
exporter = new JRDocxExporter();
break;
case XLSX:
return new JRXlsxExporter();
writerOutput = false;
exporter = new JRXlsxExporter();
break;
case PPTX:
return new JRPptxExporter();
writerOutput = false;
exporter = new JRPptxExporter();
break;
default:
return null;
}
//noinspection unchecked
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
ExporterOutput output = writerOutput
? new SimpleWriterExporterOutput(destinationFileName)
: new SimpleOutputStreamExporterOutput(destinationFileName);
//noinspection unchecked
exporter.setExporterOutput(output);
return exporter;
}

public static String getDateTime() {
Expand Down
Expand Up @@ -22,6 +22,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.security.access.ConfigAttribute;
Expand Down Expand Up @@ -181,14 +182,14 @@ public static List<NonceCredentialsPolicyType> getEffectiveNonceCredentialsPolic
}

public static NonceCredentialsPolicyType getEffectiveNonceCredentialsPolicy(SecurityPolicyType securityPolicy) throws SchemaException {
List<NonceCredentialsPolicyType> noncePolies = getEffectiveNonceCredentialsPolicies(securityPolicy);
if (noncePolies.isEmpty()) {
List<NonceCredentialsPolicyType> noncePolicies = getEffectiveNonceCredentialsPolicies(securityPolicy);
if (CollectionUtils.isEmpty(noncePolicies)) {
return null;
}
if (noncePolies.size() > 1) {
if (noncePolicies.size() > 1) {
throw new SchemaException("More than one nonce policy");
}
return noncePolies.get(0);
return noncePolicies.get(0);
}

private static void copyDefaults(CredentialPolicyType defaults,
Expand Down

0 comments on commit b07b27e

Please sign in to comment.