You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2019/11/27 11:20:39 UTC
[isis] 02/10: ISIS-2186: excel module now compiles,
at least (not yet tested at all).
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2186
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 647001f626f78d54dab1b2d6f486d19244d28a9c
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Nov 21 18:36:51 2019 +0000
ISIS-2186: excel module now compiles, at least (not yet tested at all).
---
.../isis/applib/annotation/DomainObject.java | 2 +-
.../isisaddons/module/excel/dom/ExcelFixture.java | 7 +-
.../isisaddons/module/excel/dom/ExcelService.java | 5 +-
.../isisaddons/module/excel/dom/WorksheetSpec.java | 16 +--
.../module/excel/dom/util/ExcelConverter.java | 116 +++++++++------------
.../module/excel/dom/util/ExcelServiceImpl.java | 21 +++-
.../module/excel/dom/util/PivotUtils.java | 35 +++----
.../module/excel/dom/util/SheetPivoter.java | 42 ++++----
.../module/excel/dom/util/PivotUtilsTest.java | 11 +-
.../module/excel/dom/util/SheetPivoterTest.java | 11 +-
10 files changed, 137 insertions(+), 129 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObject.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObject.java
index 34e4134..391e992 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObject.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObject.java
@@ -42,7 +42,7 @@ import org.apache.isis.applib.events.lifecycle.ObjectUpdatingEvent;
*
* @apiNote Meta annotation {@link Component} allows for the Spring framework to pick up (discover) the
* annotated type.
- * For more details see {@link org.apache.isis.config.beans.IsisBeanFactoryPostProcessorForSpring}.
+ * For more details see <code>org.apache.isis.config.beans.IsisBeanFactoryPostProcessorForSpring</code>
*/
@Inherited
@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
diff --git a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/ExcelFixture.java b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/ExcelFixture.java
index a9186c7..c8bff95 100644
--- a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/ExcelFixture.java
+++ b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/ExcelFixture.java
@@ -11,6 +11,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.io.Resources;
+import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.isis.extensions.fixtures.fixturescripts.FixtureResultList;
import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScript;
import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
@@ -27,6 +28,7 @@ import org.apache.isis.applib.value.Blob;
import org.isisaddons.module.excel.dom.util.ExcelServiceImpl;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
@@ -36,6 +38,7 @@ import lombok.Setter;
@DomainObject(
objectType = "isisexcel.ExcelFixture"
)
+@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
public class ExcelFixture extends FixtureScript {
private final List<Class> classes;
@@ -115,7 +118,7 @@ public class ExcelFixture extends FixtureScript {
protected void execute(final ExecutionContext ec) {
final ExcelServiceImpl excelServiceImpl = new ExcelServiceImpl();
- serviceRegistry.injectServicesInto(excelServiceImpl);
+ serviceInjector.injectServicesInto(excelServiceImpl);
if (blob == null){
byte[] bytes = getBytes();
@@ -215,6 +218,6 @@ public class ExcelFixture extends FixtureScript {
@javax.inject.Inject
private BookmarkService bookmarkService;
@javax.inject.Inject
- private ServiceRegistry serviceRegistry;
+ private ServiceInjector serviceInjector;
}
diff --git a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/ExcelService.java b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/ExcelService.java
index 8822d16..625e670 100644
--- a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/ExcelService.java
+++ b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/ExcelService.java
@@ -11,6 +11,7 @@ import javax.inject.Inject;
import com.google.common.collect.Lists;
+import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -55,7 +56,7 @@ public class ExcelService {
@PostConstruct
public void init(final Map<String,String> properties) {
excelServiceImpl = new ExcelServiceImpl();
- serviceRegistry.injectServicesInto(excelServiceImpl);
+ serviceInjector.injectServicesInto(excelServiceImpl);
}
// //////////////////////////////////////
@@ -227,6 +228,6 @@ public class ExcelService {
}
@Inject BookmarkService bookmarkService;
- @Inject ServiceRegistry serviceRegistry;
+ @Inject ServiceInjector serviceInjector;
}
diff --git a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/WorksheetSpec.java b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/WorksheetSpec.java
index 63ec002..098ad26 100644
--- a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/WorksheetSpec.java
+++ b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/WorksheetSpec.java
@@ -1,7 +1,13 @@
package org.isisaddons.module.excel.dom;
+import lombok.Getter;
+import lombok.Setter;
+
import java.util.List;
+import javax.inject.Inject;
+
+import org.apache.isis.applib.services.inject.ServiceInjector;
import org.isisaddons.module.excel.dom.util.Mode;
public class WorksheetSpec {
@@ -19,9 +25,11 @@ public class WorksheetSpec {
Class<?> getCls();
- static class Default<T> implements RowFactory<T>, ServicesInjectorAware {
+ static class Default<T> implements RowFactory<T> {
private final Class<T> viewModelClass;
- private ServicesInjector servicesInjector;
+
+ @Inject @Setter
+ private ServiceInjector servicesInjector;
public Default(final Class<T> viewModelClass) {
this.viewModelClass = viewModelClass;
@@ -43,10 +51,6 @@ public class WorksheetSpec {
return viewModelClass;
}
- @Override
- public void setServicesInjector(final ServicesInjector servicesInjector) {
- this.servicesInjector = servicesInjector;
- }
}
}
diff --git a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/ExcelConverter.java b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/ExcelConverter.java
index 71aecb1..38579ce 100644
--- a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/ExcelConverter.java
+++ b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/ExcelConverter.java
@@ -6,11 +6,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.annotation.Nullable;
@@ -20,21 +19,19 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.isis.metamodel.adapter.ObjectAdapter;
import org.apache.isis.metamodel.consent.InteractionInitiatedBy;
+import org.apache.isis.metamodel.objectmanager.ObjectManager;
import org.apache.isis.metamodel.spec.ManagedObject;
import org.apache.isis.metamodel.spec.ObjectSpecification;
+import org.apache.isis.metamodel.spec.feature.Contributed;
import org.apache.isis.metamodel.spec.feature.ObjectAssociation;
import org.apache.isis.metamodel.spec.feature.OneToOneAssociation;
import org.apache.isis.metamodel.specloader.SpecificationLoader;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.CreationHelper;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.isis.applib.annotation.Where;
@@ -78,30 +75,27 @@ class ExcelConverter {
// //////////////////////////////////////
private final SpecificationLoader specificationLoader;
- private final AdapterManager adapterManager;
+ private final ObjectManager objectManager;
private final BookmarkService bookmarkService;
- private final ServicesInjector servicesInjector;
+ private final ServiceInjector serviceInjector;
ExcelConverter(
final SpecificationLoader specificationLoader,
- final AdapterManager adapterManager,
+ final ObjectManager objectManager,
final BookmarkService bookmarkService,
- final ServicesInjector servicesInjector) {
+ final ServiceInjector serviceInjector) {
this.specificationLoader = specificationLoader;
- this.adapterManager = adapterManager;
+ this.objectManager = objectManager;
this.bookmarkService = bookmarkService;
- this.servicesInjector = servicesInjector;
+ this.serviceInjector = serviceInjector;
}
// //////////////////////////////////////
File appendSheet(final List<WorksheetContent> worksheetContents, XSSFWorkbook workbook) throws IOException {
- final ImmutableSet<String> worksheetNames = FluentIterable.from(worksheetContents)
- .transform(new Function<WorksheetContent, String>() {
- @Nullable @Override public String apply(@Nullable final WorksheetContent worksheetContent) {
- return worksheetContent.getSpec().getSheetName();
- }
- }).toSet();
+ final Set<String> worksheetNames = worksheetContents.stream()
+ .map(x -> x.getSpec().getSheetName())
+ .collect(Collectors.toSet());
if(worksheetNames.size() < worksheetContents.size()) {
throw new IllegalArgumentException("Sheet names must have distinct names");
}
@@ -134,18 +128,17 @@ class ExcelConverter {
final ObjectSpecification objectSpec = specificationLoader.loadSpecification(factory.getCls());
- final List<ManagedObject> adapters = Lists.transform(domainObjects, ObjectAdapter.Functions.adapterForUsing(adapterManager));
+ final List<ManagedObject> adapters = domainObjects.stream().map(objectManager::adapt).collect(Collectors.toList());
- @SuppressWarnings("deprecation")
- final List<? extends ObjectAssociation> propertyList = objectSpec.getAssociations(VISIBLE_PROPERTIES);
+ final List<ObjectAssociation> propertyList = objectSpec.streamAssociations(Contributed.INCLUDED)
+ .filter(VISIBLE_PROPERTIES)
+ .collect(Collectors.toList());
List<ObjectAssociation> annotatedAsHyperlink = new ArrayList<>();
for (Field f : fieldsAnnotatedWith(factory.getCls(), HyperLink.class)){
- for (ObjectAssociation oa :propertyList){
- if (oa.getId().equals(f.getName())){
- annotatedAsHyperlink.add(oa);
- }
- }
+ propertyList.stream()
+ .filter(oa -> Objects.equals(oa.getId(), f.getName()))
+ .forEach(annotatedAsHyperlink::add);
}
final Sheet sheet = ((Workbook) workbook).createSheet(sheetName);
@@ -224,10 +217,9 @@ class ExcelConverter {
final ObjectSpecification objectSpec = specificationLoader.loadSpecification(factory.getCls());
- final List<ObjectAdapter> adapters = Lists.transform(domainObjects, ObjectAdapter.Functions.adapterForUsing(adapterManager));
-
- @SuppressWarnings("deprecation")
- final List<? extends ObjectAssociation> propertyList = objectSpec.getAssociations(VISIBLE_PROPERTIES);
+ final List<ObjectAssociation> propertyList = objectSpec.streamAssociations(Contributed.INCLUDED)
+ .filter(VISIBLE_PROPERTIES)
+ .collect(Collectors.toList());
// Validate the annotations for pivot
validateAnnotations(propertyList, factory.getCls());
@@ -366,11 +358,7 @@ class ExcelConverter {
final WorksheetSpec worksheetSpec) {
final WorksheetSpec.RowFactory<Object> factory = worksheetSpec.getFactory();
- if(factory instanceof ServicesInjectorAware) {
- final ServicesInjectorAware servicesInjectorAware = (ServicesInjectorAware) factory;
- servicesInjectorAware.setServicesInjector(this.servicesInjector);
-
- }
+ this.serviceInjector.injectServicesInto(factory);
final Class<T> cls = (Class<T>) factory.getCls();
final String sheetName = worksheetSpec.getSheetName();
@@ -393,7 +381,7 @@ class ExcelConverter {
for (final Cell cell : row) {
try{
- if (cell.getCellType() != Cell.CELL_TYPE_BLANK) {
+ if (cell.getCellType() != CellType.BLANK) {
final int columnIndex = cell.getColumnIndex();
final String propertyName = cellMarshaller.getStringCellValue(cell);
final OneToOneAssociation property = getAssociation(objectSpec, propertyName);
@@ -419,7 +407,7 @@ class ExcelConverter {
// Let's require at least one column to be not null for detecting a blank row.
// Excel can have physical rows with cells empty that it seem do not existent for the user.
- ObjectAdapter templateAdapter = null;
+ ManagedObject templateAdapter = null;
T imported = null;
for (final Cell cell : row) {
@@ -441,9 +429,9 @@ class ExcelConverter {
importedEnhanced.setExcelSheetName(sheetName);
imported = (T) importedEnhanced;
}
- templateAdapter = this.adapterManager.adapterFor(imported);
+ templateAdapter = this.objectManager.adapt(imported);
}
- final ObjectAdapter valueAdapter = this.adapterManager.adapterFor(value);
+ final ManagedObject valueAdapter = this.objectManager.adapt(value);
otoa.set(templateAdapter, valueAdapter, InteractionInitiatedBy.USER);
}
} else {
@@ -462,13 +450,17 @@ class ExcelConverter {
}
}
- // we need to remove the templateAdapter because earlier on we will have created an adapter (and corresponding OID)
- // for a view model where the OID is initially computed on the incomplete (in fact, empty) view model.
- // removing the adapter therefore removes the OID as well, so next time an adapter is needed for the view model
- // the OID will be recomputed based on the fully populated view model pojo.
- if(templateAdapter != null) {
- this.adapterManager.removeAdapter(templateAdapter);
- }
+ //
+ // TODO: v2: to review... there is no longer an API to remove adapters.
+ // However, my hope is that it isn't needed, because we no longer maintain an oid <-> adapter map.
+ //
+// // we need to remove the templateAdapter because earlier on we will have created an adapter (and corresponding OID)
+// // for a view model where the OID is initially computed on the incomplete (in fact, empty) view model.
+// // removing the adapter therefore removes the OID as well, so next time an adapter is needed for the view model
+// // the OID will be recomputed based on the fully populated view model pojo.
+// if(templateAdapter != null) {
+// this.objectManager.removeAdapter(templateAdapter);
+// }
if (imported != null) {
importedItems.add(imported);
@@ -518,18 +510,14 @@ class ExcelConverter {
}
private static OneToOneAssociation getAssociation(final ObjectSpecification objectSpec, final String propertyNameOrId) {
- final List<ObjectAssociation> associations = objectSpec.getAssociations(Contributed.INCLUDED);
- for (final ObjectAssociation association : associations) {
- if (association instanceof OneToOneAssociation) {
- if (propertyNameOrId.equalsIgnoreCase(association.getName())) {
- return (OneToOneAssociation) association;
- }
- if (propertyNameOrId.equalsIgnoreCase(association.getId())) {
- return (OneToOneAssociation) association;
- }
- }
- }
- return null;
+ final Stream<ObjectAssociation> associations = objectSpec.streamAssociations(Contributed.INCLUDED);
+ return associations
+ .filter(OneToOneAssociation.class::isInstance)
+ .map(OneToOneAssociation.class::cast)
+ .filter(association -> propertyNameOrId.equalsIgnoreCase(association.getName())
+ || propertyNameOrId.equalsIgnoreCase(association.getId()))
+ .findFirst()
+ .orElse(null);
}
static class Property {
@@ -591,13 +579,13 @@ class ExcelConverter {
final short dateFormat = createHelper.createDataFormat().getFormat("yyyy-mm-dd");
final CellStyle dateCellStyle = wb.createCellStyle();
dateCellStyle.setDataFormat(dateFormat);
- dateCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
+ dateCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
return dateCellStyle;
}
protected CellStyle defaultCellStyle(final Workbook wb) {
final CellStyle defaultCellStyle = wb.createCellStyle();
- defaultCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
+ defaultCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
return defaultCellStyle;
}
diff --git a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/ExcelServiceImpl.java b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/ExcelServiceImpl.java
index 45757bd..b0ecaab 100644
--- a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/ExcelServiceImpl.java
+++ b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/ExcelServiceImpl.java
@@ -1,11 +1,20 @@
package org.isisaddons.module.excel.dom.util;
+import lombok.SneakyThrows;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
-
+import java.util.function.Supplier;
+
+import org.apache.isis.applib.services.inject.ServiceInjector;
+import org.apache.isis.commons.internal.exceptions._Exceptions;
+import org.apache.isis.metamodel.objectmanager.ObjectManager;
+import org.apache.isis.metamodel.specloader.SpecificationLoader;
+import org.apache.isis.runtime.system.context.session.RuntimeContextBase;
+import org.apache.isis.runtime.system.session.IsisSession;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.isis.applib.annotation.Programmatic;
@@ -212,8 +221,10 @@ public class ExcelServiceImpl {
}
}
+ @SneakyThrows
private ExcelConverter newExcelConverter() {
- return new ExcelConverter(getSpecificationLoader(), getPersistenceSession(), bookmarkService, isisSessionFactory.getServicesInjector());
+ final ObjectManager objectManager = IsisSession.current().map(RuntimeContextBase::getObjectManager).orElseThrow((Supplier<Throwable>) _Exceptions::unexpectedCodeReach);
+ return new ExcelConverter(specificationLoader, objectManager, bookmarkService, serviceInjector);
}
@@ -223,6 +234,12 @@ public class ExcelServiceImpl {
@javax.inject.Inject
BookmarkService bookmarkService;
+ @javax.inject.Inject
+ SpecificationLoader specificationLoader;
+
+ @javax.inject.Inject
+ ServiceInjector serviceInjector;
+
// @javax.inject.Inject
// IsisSessionFactory isisSessionFactory;
//
diff --git a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/PivotUtils.java b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/PivotUtils.java
index 8efb137..1c2612e 100644
--- a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/PivotUtils.java
+++ b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/PivotUtils.java
@@ -3,6 +3,7 @@ package org.isisaddons.module.excel.dom.util;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.isisaddons.module.excel.dom.AggregationType;
@@ -46,35 +47,33 @@ public class PivotUtils {
if (cell != null && other != null && cell.getCellType() == other.getCellType()) {
switch (cell.getCellType()) {
- case Cell.CELL_TYPE_BLANK:
- if (other.getCellType()==Cell.CELL_TYPE_BLANK){
+ case BLANK:
+ if (other.getCellType()==CellType.BLANK) {
return true;
}
break;
- case Cell.CELL_TYPE_BOOLEAN:
+ case BOOLEAN:
if (cell.getBooleanCellValue() == other.getBooleanCellValue()){
return true;
}
break;
- case Cell.CELL_TYPE_ERROR:
+ case ERROR:
if (cell.getErrorCellValue() == other.getErrorCellValue()){
return true;
}
break;
- case Cell.CELL_TYPE_FORMULA:
+ case FORMULA:
break;
- case Cell.CELL_TYPE_NUMERIC:
+ case NUMERIC:
if (cell.getNumericCellValue() == other.getNumericCellValue()){
return true;
}
break;
- case Cell.CELL_TYPE_STRING:
+ case STRING:
if (cell.getStringCellValue().equals(other.getStringCellValue())){
return true;
}
-
}
-
}
return false;
@@ -86,7 +85,7 @@ public class PivotUtils {
return target;
}
- if (target.getCellType()==Cell.CELL_TYPE_NUMERIC && source.getCellType()==Cell.CELL_TYPE_NUMERIC ){
+ if (target.getCellType()==CellType.NUMERIC && source.getCellType()==CellType.NUMERIC ){
double val1 = target.getNumericCellValue();
double val2 = source.getNumericCellValue();
target.setCellValue(val1+val2);
@@ -115,26 +114,24 @@ public class PivotUtils {
target.setHyperlink(source.getHyperlink());
}
- // Set the cell data type
- target.setCellType(source.getCellType());
-
// Set the cell data value
switch (source.getCellType()) {
- case Cell.CELL_TYPE_BLANK:
+ case BLANK:
+ target.setBlank();
break;
- case Cell.CELL_TYPE_BOOLEAN:
+ case BOOLEAN:
target.setCellValue(source.getBooleanCellValue());
break;
- case Cell.CELL_TYPE_ERROR:
+ case ERROR:
target.setCellErrorValue(source.getErrorCellValue());
break;
- case Cell.CELL_TYPE_FORMULA:
+ case FORMULA:
target.setCellFormula(source.getCellFormula());
break;
- case Cell.CELL_TYPE_NUMERIC:
+ case NUMERIC:
target.setCellValue(source.getNumericCellValue());
break;
- case Cell.CELL_TYPE_STRING:
+ case STRING:
target.setCellValue(source.getRichStringCellValue());
break;
}
diff --git a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/SheetPivoter.java b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/SheetPivoter.java
index e87571c..4cbbe28 100644
--- a/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/SheetPivoter.java
+++ b/extensions/lib/excel/impl/src/main/java/org/isisaddons/module/excel/dom/util/SheetPivoter.java
@@ -7,11 +7,7 @@ import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellReference;
import org.isisaddons.module.excel.dom.AggregationType;
@@ -59,9 +55,9 @@ public class SheetPivoter {
final static int columnLabelOffsetY = 0; // top row used for pivot
//some styling
- final static short fieldnameBgColorIndex = HSSFColor.GREY_25_PERCENT.index;
- final static short columnHeaderValueBgColorIndex = HSSFColor.GREY_40_PERCENT.index;
- final static short sumBgColorIndex = HSSFColor.GREY_25_PERCENT.index;
+ final static short fieldnameBgColorIndex = HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex();
+ final static short columnHeaderValueBgColorIndex = HSSFColor.HSSFColorPredefined.GREY_40_PERCENT.getIndex();
+ final static short sumBgColorIndex = HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex();
static CellStyle fieldNameStyle;
static CellStyle columnHeaderValueStyle;
static CellStyle rowSumStyle;
@@ -205,11 +201,11 @@ public class SheetPivoter {
cell.setCellValue("(empty)");
return cell;
}
- if (cell.getCellType()==Cell.CELL_TYPE_BLANK){
+ if (cell.getCellType()== CellType.BLANK){
cell.setCellValue("(empty)");
return cell;
}
- if (cell.getCellType()==Cell.CELL_TYPE_STRING && cell.getStringCellValue().equals("")){
+ if (cell.getCellType()==CellType.STRING && cell.getStringCellValue().equals("")){
cell.setCellValue("(empty)");
}
return cell;
@@ -221,8 +217,8 @@ public class SheetPivoter {
for (AnnotationTriplet at : annotations.getByAnnotation_OrderBy_OrderAscending("value")){
for (srCnt = SourceLayOut.VALUES_START_AT_ROWNUMBER; srCnt <= sourceSheet.getLastRowNum(); srCnt++){
Cell c = sourceSheet.getRow(srCnt).getCell(at.getColnumber());
- if (c != null && c.getCellType()!=Cell.CELL_TYPE_BLANK){
- if (c.getCellType()!=Cell.CELL_TYPE_NUMERIC) {
+ if (c != null && c.getCellType()!=CellType.BLANK){
+ if (c.getCellType()!=CellType.NUMERIC) {
badData = true;
continue;
}
@@ -424,7 +420,7 @@ public class SheetPivoter {
// copy or add value to target cell
Cell valueCellSource = sourceSheet.getRow(rowInSource).getCell(colInSource);
Cell valueCellTarget = targetSheet.getRow(rowInTarget).getCell(colPosTarget);
- if (valueCellSource!=null && (valueCellTarget== null || valueCellTarget.getCellType()==Cell.CELL_TYPE_BLANK)){
+ if (valueCellSource!=null && (valueCellTarget== null || valueCellTarget.getCellType()==CellType.BLANK)){
valueCellTarget = targetSheet.getRow(rowInTarget).createCell(colPosTarget);
switch (type) {
case SUM:
@@ -569,33 +565,33 @@ public class SheetPivoter {
private void defineSomeCellStyles() {
TargetLayOut.boldFont= targetSheet.getWorkbook().createFont();
- TargetLayOut.boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
+ TargetLayOut.boldFont.setBold(true);
TargetLayOut.fieldNameStyle = targetSheet.getWorkbook().createCellStyle();
TargetLayOut.fieldNameStyle.setFillForegroundColor(TargetLayOut.fieldnameBgColorIndex);
- TargetLayOut.fieldNameStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
+ TargetLayOut.fieldNameStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
TargetLayOut.fieldNameStyle.setFont(TargetLayOut.boldFont);
TargetLayOut.columnHeaderValueStyle = targetSheet.getWorkbook().createCellStyle();
TargetLayOut.columnHeaderValueStyle.setFillForegroundColor(TargetLayOut.columnHeaderValueBgColorIndex);
- TargetLayOut.columnHeaderValueStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
+ TargetLayOut.columnHeaderValueStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
TargetLayOut.columnHeaderValueStyle.setFont(TargetLayOut.boldFont);
TargetLayOut.rowSumStyle = targetSheet.getWorkbook().createCellStyle();
- TargetLayOut.rowSumStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+ TargetLayOut.rowSumStyle.setBorderLeft(BorderStyle.THIN);
TargetLayOut.rowSumStyle.setFillForegroundColor(TargetLayOut.sumBgColorIndex);
- TargetLayOut.rowSumStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
+ TargetLayOut.rowSumStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
TargetLayOut.columSumStyle = targetSheet.getWorkbook().createCellStyle();
- TargetLayOut.columSumStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
+ TargetLayOut.columSumStyle.setBorderTop(BorderStyle.THIN);
TargetLayOut.columSumStyle.setFillForegroundColor(TargetLayOut.sumBgColorIndex);
- TargetLayOut.columSumStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
+ TargetLayOut.columSumStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
TargetLayOut.totalSumStyle = targetSheet.getWorkbook().createCellStyle();
- TargetLayOut.totalSumStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
- TargetLayOut.totalSumStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+ TargetLayOut.totalSumStyle.setBorderTop(BorderStyle.THIN);
+ TargetLayOut.totalSumStyle.setBorderLeft(BorderStyle.THIN);
TargetLayOut.totalSumStyle.setFillForegroundColor(TargetLayOut.sumBgColorIndex);
- TargetLayOut.totalSumStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
+ TargetLayOut.totalSumStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
}
}
diff --git a/extensions/lib/excel/impl/src/test/java/org/isisaddons/module/excel/dom/util/PivotUtilsTest.java b/extensions/lib/excel/impl/src/test/java/org/isisaddons/module/excel/dom/util/PivotUtilsTest.java
index ae87b39..b41cffc 100644
--- a/extensions/lib/excel/impl/src/test/java/org/isisaddons/module/excel/dom/util/PivotUtilsTest.java
+++ b/extensions/lib/excel/impl/src/test/java/org/isisaddons/module/excel/dom/util/PivotUtilsTest.java
@@ -5,6 +5,7 @@ import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -100,9 +101,9 @@ public class PivotUtilsTest {
// when (type not equal)
c1 = r.createCell(0);
- c1.setCellType(Cell.CELL_TYPE_BLANK);
+ c1.setCellType(CellType.BLANK);
c2 = r.createCell(1);
- c2.setCellType(Cell.CELL_TYPE_BOOLEAN);
+ c2.setCellType(CellType.BOOLEAN);
// then
Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false);
@@ -142,7 +143,7 @@ public class PivotUtilsTest {
c1 = r.createCell(0);
c2 = r.createCell(1);
c1.setCellValue("a");
- c2.setCellType(Cell.CELL_TYPE_NUMERIC);
+ c2.setCellType(CellType.NUMERIC);
// then
Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false);
@@ -173,7 +174,7 @@ public class PivotUtilsTest {
// when 0 (false) 1 (true) value in boolean cell supported
c1.setCellValue(true);
c2.setCellValue(1);
- c2.setCellType(Cell.CELL_TYPE_BOOLEAN);
+ c2.setCellType(CellType.BOOLEAN);
// then
Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(true);
@@ -255,7 +256,7 @@ public class PivotUtilsTest {
// then
Assertions.assertThat(cTarget).isEqualTo(cSource);
- Assertions.assertThat(cTarget.getCellType()).isEqualTo(Cell.CELL_TYPE_BLANK);
+ Assertions.assertThat(cTarget.getCellType()).isEqualTo(CellType.BLANK);
// given source has a value
cSource = r.createCell(1);
diff --git a/extensions/lib/excel/impl/src/test/java/org/isisaddons/module/excel/dom/util/SheetPivoterTest.java b/extensions/lib/excel/impl/src/test/java/org/isisaddons/module/excel/dom/util/SheetPivoterTest.java
index c239df8..21b0b6a 100644
--- a/extensions/lib/excel/impl/src/test/java/org/isisaddons/module/excel/dom/util/SheetPivoterTest.java
+++ b/extensions/lib/excel/impl/src/test/java/org/isisaddons/module/excel/dom/util/SheetPivoterTest.java
@@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -33,7 +34,7 @@ public class SheetPivoterTest {
// when
Cell c = targetSheet.createRow(0).createCell(0);
- c.setCellValue(Cell.CELL_TYPE_BLANK);
+ c.setBlank();
// then
// ************** NOTE ***************************************************************************
@@ -49,7 +50,7 @@ public class SheetPivoterTest {
// then still
Assertions.assertThat(targetSheet.getRow(0).getLastCellNum()).isEqualTo((short)1); // NOTE !!!!!!!
- Assertions.assertThat(c.getCellType()).isEqualTo(Cell.CELL_TYPE_STRING);
+ Assertions.assertThat(c.getCellType()).isEqualTo(CellType.STRING);
// and when
targetSheet.getRow(0).createCell(1).setCellValue("b");
@@ -81,8 +82,8 @@ public class SheetPivoterTest {
testRow(0, "fn3", null);
testRow(1, "fn1", null);
// last row is for summing
- Assertions.assertThat(targetSheet.getRow(2).getCell(0).getCellType()).isEqualTo(Cell.CELL_TYPE_BLANK);
- Assertions.assertThat(targetSheet.getRow(2).getCell(1).getCellType()).isEqualTo(Cell.CELL_TYPE_FORMULA);
+ Assertions.assertThat(targetSheet.getRow(2).getCell(0).getCellType()).isEqualTo(CellType.BLANK);
+ Assertions.assertThat(targetSheet.getRow(2).getCell(1).getCellType()).isEqualTo(CellType.FORMULA);
Assertions.assertThat(targetSheet.getRow(2).getCell(1).getCellFormula()).isEqualTo("SUM(B3:B2)");
}
@@ -435,7 +436,7 @@ public class SheetPivoterTest {
if (c == null) {
// OK skip
} else {
- if (c.getCellType() == Cell.CELL_TYPE_NUMERIC) {
+ if (c.getCellType() == CellType.NUMERIC) {
Assertions.assertThat(c.getNumericCellValue()).isEqualTo(null);
} else {
Assertions.assertThat(c.getStringCellValue()).isEqualTo("");