avancement template + excel

This commit is contained in:
guillaume 2019-02-07 11:45:07 +01:00
commit 7ef810b391
14 changed files with 525 additions and 180 deletions

View file

@ -12,8 +12,8 @@
<artifactId>drools-framework-admin-console</artifactId>
<properties>
<vaadin.version>12.0.2</vaadin.version>
<spring-boot.version>2.1.0.RELEASE</spring-boot.version>
<vaadin.version>12.0.5</vaadin.version>
<spring-boot.version>2.1.2.RELEASE</spring-boot.version>
<spring-version>5.1.2.RELEASE</spring-version>
<webapp.directory>src/main/webapp</webapp.directory>
<jbpm.version>7.15.0.Final</jbpm.version>
@ -57,6 +57,19 @@
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.kie.server</groupId>
<artifactId>kie-server-api</artifactId>
@ -93,10 +106,19 @@
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-upload-flow</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.vaadin.olli</groupId>
<artifactId>file-download-wrapper</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>

View file

@ -0,0 +1,153 @@
package org.chtijbug.drools.console.service;
import javassist.bytecode.ByteArray;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.chtijbug.drools.console.service.model.kie.KieConfigurationData;
import org.chtijbug.drools.console.service.util.AppContext;
import org.drools.workbench.models.datamodel.rule.InterpolationVariable;
import org.drools.workbench.models.guided.template.backend.RuleTemplateModelXMLPersistenceImpl;
import org.drools.workbench.models.guided.template.shared.TemplateModel;
import org.springframework.stereotype.Service;
import java.io.*;
import java.util.*;
@Service
public class ExcelService {
private KieRepositoryService kieRepositoryService;
private KieConfigurationData config;
private UserConnectedService userConnectedService;
public ExcelService(){
this.kieRepositoryService = AppContext.getApplicationContext().getBean(KieRepositoryService.class);
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
this.userConnectedService = AppContext.getApplicationContext().getBean(UserConnectedService.class);
}
public List<HashMap<String,Object>> importExcel(InputStream inputStream) throws IOException {
Workbook workbook= WorkbookFactory.create(inputStream);
DataFormatter dataFormatter = new DataFormatter();
List<HashMap<String,Object>> result=new ArrayList<>();
for(Sheet sheet: workbook) {
for (Row row: sheet) {
if(row.getRowNum()!=0) {
HashMap<String, Object> tmp = new HashMap<>();
result.add(tmp);
for (Cell cell : row) {
String cellValue = dataFormatter.formatCellValue(cell);
Integer numColumn = cell.getColumnIndex();
Cell title = sheet.getRow(0).getCell(numColumn);
tmp.put(dataFormatter.formatCellValue(title), cellValue);
}
}
}
}
return result;
}
public ByteArrayInputStream exportExcel(String nameTemplate){
//Récupération des objets JAVA
String assetContent = kieRepositoryService.getAssetSource(config.getKiewbUrl(),
userConnectedService.getUserConnected().getUserName(),
userConnectedService.getUserConnected().getUserPassword(),
userConnectedService.getSpace(),
userConnectedService.getProject(),
userConnectedService.getAsset());
TemplateModel model = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(assetContent);
InterpolationVariable[] variablesList = model.getInterpolationVariablesList();
String[][] contenuTable = model.getTableAsArray();
List<HashMap<String, Object>> rows = new ArrayList<>();
for (int i = 0; i < model.getRowsCount(); i++) {
HashMap<String, Object> newRow = new HashMap<>();
rows.add(newRow);
String[] ligne = contenuTable[i];
int k = 0;
for (InterpolationVariable j : variablesList) {
newRow.put(j.getVarName(), ligne[k]);
k++;
}
}
Workbook workbook = new XSSFWorkbook();
CreationHelper createHelper = workbook.getCreationHelper();
Sheet sheet = workbook.createSheet(nameTemplate);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setColor(IndexedColors.BLACK.getIndex());
CellStyle headerCellStyle = workbook.createCellStyle();
headerCellStyle.setFont(headerFont);
Row headerRow=sheet.createRow(0);
if(rows!=null&&rows.size()!=0){
int columnIndex=0;
for(Map.Entry<String,Object> t:rows.get(0).entrySet()){
Cell cell=headerRow.createCell(columnIndex);
cell.setCellValue(t.getKey());
cell.setCellStyle(headerCellStyle);
columnIndex++;
}
int rowIndex=1;
for(HashMap<String,Object> t:rows) {
int columnIndexTmp=0;
Row r=sheet.createRow(rowIndex);
for (Map.Entry<String, Object> tmp : t.entrySet()) {
Cell cell=r.createCell(columnIndexTmp);
cell.setCellValue(String.valueOf(tmp.getValue()));
cell.setCellStyle(headerCellStyle);
columnIndexTmp++;
}
rowIndex++;
}
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
FileOutputStream fileOutputStream=new FileOutputStream("/home/guillaume/test.xlsx");
workbook.write(fileOutputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
workbook.write(bos);
} catch (IOException e) {
e.printStackTrace();
}
byte[] barray = bos.toByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(barray);
try {
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
return is;
}
}

View file

@ -9,20 +9,18 @@ import org.chtijbug.drools.console.service.model.kie.JobStatus;
import org.chtijbug.guvnor.server.jaxrs.api.UserLoginInformation;
import org.chtijbug.guvnor.server.jaxrs.jaxb.Asset;
import org.chtijbug.guvnor.server.jaxrs.model.PlatformProjectResponse;
import org.drools.workbench.models.guided.template.backend.RuleTemplateModelXMLPersistenceImpl;
import org.drools.workbench.models.guided.template.shared.TemplateModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RequestCallback;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.*;
@Service
public class KieRepositoryService {
@ -35,8 +33,57 @@ public class KieRepositoryService {
private ObjectMapper mapper = new ObjectMapper();
private String pojoToStringMethod(String assetContent,List<HashMap<String,Object>> objects){
public String getAssetSource(String url, String username, String password, String spaceName, String projectName, String assetName) {
TemplateModel model = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(assetContent);
int i=0;
model.clearRows();
for(HashMap<String,Object> t:objects){
List<String> row=new ArrayList<>();
for (Map.Entry<String,Object> entry:t.entrySet()){
row.add(String.valueOf(entry.getValue()));
}
model.addRow(i,row.toArray(new String[row.size()]));
i++;
}
return RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(model);
}
public void updateAssetSource(String url, String username, String password, String spaceName, String projectName, String assetName,List<HashMap<String,Object>> objects) {
String assetContent = getAssetSource(url,
username,
password,
spaceName,
projectName,
assetName);
String completeurl = url + "/chtijbug/" + spaceName + "/" + projectName + "/assets/" + assetName + "/source";
String content=pojoToStringMethod(assetContent,objects);
logger.info("url moteur reco : " + completeurl);
ResponseEntity response = restTemplateKiewb
.execute(completeurl, HttpMethod.POST, requestCallback(content, username, password), clientHttpResponse -> {
String extractedResponse = null;
if (clientHttpResponse.getBody() != null) {
Scanner s = new Scanner(clientHttpResponse.getBody()).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
extractedResponse = result;
}
ResponseEntity extractedValue = new ResponseEntity<>(extractedResponse, clientHttpResponse.getHeaders(), clientHttpResponse.getStatusCode());
return extractedValue;
});
// restTemplateKiewb.exchange(completeurl, HttpMethod.POST, requestCallBack(content, username, password), void.class);
System.out.println("");
}
public String getAssetSource(String url, String username, String password, String spaceName, String projectName, String assetName) {
String completeurl = url + "/chtijbug/" + spaceName + "/" + projectName + "/assets/" + assetName + "/source";
logger.info("url moteur reco : " + completeurl);
ResponseEntity<String> response = restTemplateKiewb
@ -169,6 +216,23 @@ public class KieRepositoryService {
return reponseMoteur;
}
private HttpEntity requestCallBack(final Object content, String username, String password){
HttpHeaders httpHeaders=new HttpHeaders();
httpHeaders.add(
HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
httpHeaders.add(
HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
String auth = username + ":" + password;
byte[] encodedAuth = Base64.encodeBase64(
auth.getBytes(Charset.forName("UTF-8")));
String authHeader = "Basic " + new String(encodedAuth);
httpHeaders.add(
HttpHeaders.AUTHORIZATION, authHeader);
HttpEntity httpEntity=new HttpEntity(content,httpHeaders);
return httpEntity;
}
private RequestCallback requestCallback(final Object content, String username, String password) {
return clientHttpRequest -> {

View file

@ -27,21 +27,12 @@ import java.time.ZoneId;
import java.util.*;
@StyleSheet("css/accueil.css")
public class AssetEdit extends VerticalLayout {
public class AssetEdit extends Grid<HashMap<String, Object>> {
private KieRepositoryService kieRepositoryService;
private KieConfigurationData config;
private UserConnected userConnected;
private String assetToUpdate;
private XmlMapper mapper = new XmlMapper();
private Grid<Map<String, Object>> gridAssetTable;
private Button startUpdate;
private Button commitUpdate;
private Button undoUpdate;
private UserConnectedService userConnectedService;
private String spaceName;
private String projectName;
public AssetEdit() {
@ -50,171 +41,65 @@ public class AssetEdit extends VerticalLayout {
this.kieRepositoryService = AppContext.getApplicationContext().getBean(KieRepositoryService.class);
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
this.userConnectedService = AppContext.getApplicationContext().getBean(UserConnectedService.class);
this.userConnected = userConnectedService.getUserConnected();
this.assetToUpdate = userConnectedService.getAsset();
this.spaceName = userConnectedService.getSpace();
this.projectName = userConnectedService.getProject();
String assetContent = kieRepositoryService.getAssetSource(config.getKiewbUrl(), userConnected.getUserName(), userConnected.getUserPassword(), spaceName, projectName, assetToUpdate);
String assetContent = kieRepositoryService.getAssetSource(config.getKiewbUrl(),
userConnectedService.getUserConnected().getUserName(),
userConnectedService.getUserConnected().getUserPassword(),
userConnectedService.getSpace(),
userConnectedService.getProject(),
userConnectedService.getAsset());
TemplateModel model = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(assetContent);
HorizontalLayout actionButtons = new HorizontalLayout();
add(actionButtons);
startUpdate = new Button("Update");
actionButtons.add(startUpdate);
startUpdate.addClickListener(event -> {
startUpdate.setEnabled(false);
commitUpdate.setEnabled(true);
undoUpdate.setEnabled(true);
gridAssetTable.setEnabled(true);
//gridAssetTable.getEditor().setEnabled(true);
});
commitUpdate = new Button("Commit");
commitUpdate.setEnabled(false);
commitUpdate.addClickListener(event -> {
startUpdate.setEnabled(true);
commitUpdate.setEnabled(false);
undoUpdate.setEnabled(false);
// gridAssetTable.getEditor().setEnabled(false);
});
actionButtons.add(commitUpdate);
undoUpdate = new Button("undo");
undoUpdate.setEnabled(false);
undoUpdate.addClickListener(event -> {
startUpdate.setEnabled(true);
commitUpdate.setEnabled(false);
undoUpdate.setEnabled(false);
// gridAssetTable.getEditor().setEnabled(false);
fillTable(model);
});
actionButtons.add(undoUpdate);
InterpolationVariable[] variablesList = model.getInterpolationVariablesList();
gridAssetTable = new Grid<>();
add(gridAssetTable);
gridAssetTable.setClassName("grid-perso");
gridAssetTable.setSelectionMode(Grid.SelectionMode.SINGLE);
Binder<Map<String, Object>> binder = new Binder<>();
gridAssetTable.getEditor().setBinder(binder);
setClassName("grid-perso");
Binder<HashMap<String, Object>> binder = new Binder<>();
getEditor().setBinder(binder);
Map<String, Object> initRow = new HashMap<>();
for (InterpolationVariable i : variablesList) {
gridAssetTable.addColumn(hashmap -> hashmap.get(i.getVarName()));
/**
if (i.getDataType().equals("String")) {
Binder.Binding<Map<String, Object>, String> b = createTextField(i.getVarName(), binder);
initRow.put(i.getVarName(), i.getVarName());
gridAssetTable.addColumn(hashmap -> hashmap.get(i.getVarName()), new ComponentRenderer(()).setEditorBinding(b).setCaption(i.getVarName());
} else if (i.getDataType().equals("Date")) {
Binder.Binding<Map<String, Object>, LocalDate> b = createDateField(i.getVarName(), binder);
initRow.put(i.getVarName(), new Date());
gridAssetTable.addColumn(hashmap -> toDate((String) hashmap.get(i.getVarName())), new DateRenderer()).setId(i.getVarName()).setEditorBinding(b).setCaption(i.getVarName());
} else {
Binder.Binding<Map<String, Object>, String> b = createTextField(i.getVarName(), binder);
initRow.put(i.getVarName(), i.getVarName());
gridAssetTable.addColumn(hashmap -> hashmap.get(i.getVarName()), new com.vaadin.ui.renderers.TextRenderer()).setId(i.getVarName()).setEditorBinding(b).setCaption(i.getVarName());
}
**/
addColumn(hashmap -> hashmap.get(i.getVarName())).setHeader(i.getVarName());
}
binder.setBean(giveInitRow(model));
fillTable(model);
gridAssetTable.setSizeFull();
}
private Date toDate(String dateString) {
DateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.FRANCE);
Date result = null;
try {
result = format.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}
public AssetEdit(List<HashMap<String, Object>> objects) {
private Binder.Binding<Map<String, Object>, String> createTextField(String code, Binder<Map<String, Object>> binder) {
TextField tf = new TextField();
//tf.setWidth(250, Plotter.Unit.PIXELS);
setClassName("assetEdit-content");
//bind element
this.kieRepositoryService = AppContext.getApplicationContext().getBean(KieRepositoryService.class);
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
this.userConnectedService = AppContext.getApplicationContext().getBean(UserConnectedService.class);
Binder.Binding<Map<String, Object>, String> binding = binder.forField(tf).bind(// getter
hash -> {
return (String) hash.get(code);
},
//setter
(hash, fieldValue) -> {
hash.put(code, fieldValue);
});
return binding;
setClassName("grid-perso");
}
Binder<HashMap<String, Object>> binder = new Binder<>();
getEditor().setBinder(binder);
private Binder.Binding<Map<String, Object>, LocalDate> createDateField(String code, Binder<Map<String, Object>> binder) {
DatePicker tf = new DatePicker();
// tf.setWidth(250, Unit.PIXELS);
if(objects.size()>0){
for(Map.Entry<String,Object> t:objects.get(0).entrySet()){
addColumn(hashmap -> hashmap.get(t.getKey())).setHeader(t.getKey());
//bind element
Binder.Binding<Map<String, Object>, LocalDate> binding = binder.forField(tf).bind(// getter
hash -> {
return toLocalDate(toDate((String) hash.get(code)));
},
//setter
(hash, fieldValue) -> {
hash.put(code, toString(fieldValue));
gridAssetTable.getDataProvider().refreshAll();
});
return binding;
}
private String toString(LocalDate input) {
String result = null;
DateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.FRANCE);
Date theDate = Date.from(input.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
result = format.format(theDate);
return result;
}
private LocalDate toLocalDate(Date input) {
LocalDate result = null;
if (input != null) {
result = Instant.ofEpochMilli(input.getTime()).atZone(ZoneId.of("Europe/Paris")).toLocalDate();
}
return result;
}
private Map<String, Object> giveInitRow(TemplateModel model) {
InterpolationVariable[] variablesList = model.getInterpolationVariablesList();
Map<String, Object> newRow = new HashMap<>();
String[][] contenuTable = model.getTableAsArray();
if (contenuTable.length > 0) {
String[] ligne = contenuTable[0];
int k = 0;
for (InterpolationVariable j : variablesList) {
newRow.put(j.getVarName(), ligne[k]);
k++;
}
}
return newRow;
setItems(objects);
}
public void maj(List<HashMap<String, Object>> objects){
}
private void fillTable(TemplateModel model) {
InterpolationVariable[] variablesList = model.getInterpolationVariablesList();
DateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.FRANCE);
String[][] contenuTable = model.getTableAsArray();
List<Map<String, Object>> rows = new ArrayList<>();
List<HashMap<String, Object>> rows = new ArrayList<>();
for (int i = 0; i < model.getRowsCount(); i++) {
Map<String, Object> newRow = new HashMap<>();
HashMap<String, Object> newRow = new HashMap<>();
rows.add(newRow);
String[] ligne = contenuTable[i];
int k = 0;
@ -223,7 +108,7 @@ public class AssetEdit extends VerticalLayout {
k++;
}
}
gridAssetTable.setItems(rows);
setItems(rows);
}
}

View file

@ -123,6 +123,7 @@ public class GridActionLogging extends Grid<BusinessTransactionAction> {
addColumn(new ComponentRenderer<>(runtimePersist -> {
Checkbox label=new Checkbox();
label.setEnabled(false);
label.setValue(false);
if(runtimePersist.getInputData()!=null&&runtimePersist.getInputData().getRealFact()!=null){

View file

@ -1,9 +1,12 @@
package org.chtijbug.drools.console.vaadinComponent.leftMenu.Action;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import org.chtijbug.drools.console.vaadinComponent.ComponentPerso.ComboBoxPerso;
import org.chtijbug.drools.console.view.TemplateView;
import org.chtijbug.guvnor.server.jaxrs.model.PlatformProjectResponse;
public class TemplatesAction extends VerticalLayout {
@ -13,16 +16,28 @@ public class TemplatesAction extends VerticalLayout {
private Button edit;
private ComboBoxPerso<PlatformProjectResponse> spaceSelection;
public TemplatesAction(TemplateView templateView){
setClassName("leftMenu-global-action");
spaceSelection = new ComboBoxPerso<>("Project",VaadinIcon.SEARCH.create());
spaceSelection.getComboBox().setItems(templateView.getUserConnectedService().getUserConnected().getProjectResponses());
spaceSelection.getComboBox().setItemLabelGenerator(PlatformProjectResponse::getName);
spaceSelection.getComboBox().addValueChangeListener(valueChangeEvent -> {
templateView.setDataProvider(spaceSelection.getComboBox());
});
add(spaceSelection);
refresh =new Button("Refresh", VaadinIcon.ROTATE_LEFT.create());
refresh.setClassName("leftMenu-global-button");
add(refresh);
refresh.addClickListener(buttonClickEvent -> {
active(refresh);
templateView.refreshList();
templateView.refreshList(spaceSelection.getComboBox());
});
duplicate =new Button("Duplicate",VaadinIcon.TOOLS.create());
@ -40,7 +55,7 @@ public class TemplatesAction extends VerticalLayout {
add(edit);
edit.addClickListener(buttonClickEvent -> {
active(edit);
templateView.edit();
templateView.edit(spaceSelection.getComboBox());
});
}
private boolean isActive(Button button){
@ -58,7 +73,6 @@ public class TemplatesAction extends VerticalLayout {
removeActive(edit);
button.getClassNames().add("active");
}
public Button getRefresh() {
return refresh;
}

View file

@ -116,6 +116,7 @@ public class ActionLoggingView extends VerticalLayout {
verticalLayout.setClassName("content-action-logging");
TextArea textArea=new TextArea(b.getInputData().getFactType().name());
textArea.setReadOnly(true);
textArea.setClassName("content-log");
textArea.setValue(
b.getInputData().getRealFact().toString().replaceAll(",",",\n")
@ -147,6 +148,7 @@ public class ActionLoggingView extends VerticalLayout {
verticalLayout.setClassName("content-action-logging");
TextArea textArea=new TextArea(b.getFact().getFactType().name());
textArea.setReadOnly(true);
textArea.setClassName("content-log");
textArea.setValue(
b.getFact().getRealFact().toString().replaceAll(",",",\n")
@ -180,6 +182,7 @@ public class ActionLoggingView extends VerticalLayout {
if(fact!=null&&fact.getRealFact()!=null){
TextArea textArea=new TextArea(fact.getFactType().name());
textArea.setReadOnly(true);
textArea.setClassName("content-log");
textArea.setValue(
fact.getRealFact().toString().replaceAll(",",",\n")
@ -212,6 +215,7 @@ public class ActionLoggingView extends VerticalLayout {
if(fact!=null&&fact.getRealFact()!=null){
TextArea textArea=new TextArea(fact.getFactType().name());
textArea.setReadOnly(true);
textArea.setClassName("content-log");
textArea.setValue(
fact.getRealFact().toString().replaceAll(",",",\n")

View file

@ -0,0 +1,129 @@
package org.chtijbug.drools.console.view;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.upload.Upload;
import com.vaadin.flow.component.upload.receivers.FileBuffer;
import com.vaadin.flow.component.upload.receivers.MemoryBuffer;
import com.vaadin.flow.component.upload.receivers.MultiFileBuffer;
import com.vaadin.flow.server.StreamResource;
import org.chtijbug.drools.console.service.ExcelService;
import org.chtijbug.drools.console.service.KieRepositoryService;
import org.chtijbug.drools.console.service.UserConnectedService;
import org.chtijbug.drools.console.service.model.kie.KieConfigurationData;
import org.chtijbug.drools.console.service.util.AppContext;
import org.chtijbug.drools.console.vaadinComponent.ComponentPerso.DialogPerso;
import com.vaadin.flow.component.html.Label;
import org.chtijbug.drools.console.vaadinComponent.componentView.AssetEdit;
import org.vaadin.olli.FileDownloadWrapper;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class EditTemplateView extends VerticalLayout {
private Button exportExcel;
private Upload importExcel;
private Label title;
private AssetEdit assetEdit;
private ExcelService excelService;
private KieRepositoryService kieRepositoryService;
private KieConfigurationData config;
private UserConnectedService userConnectedService;
public EditTemplateView(DialogPerso dialogPerso,String nameTemplate){
excelService= AppContext.getApplicationContext().getBean(ExcelService.class);
kieRepositoryService=AppContext.getApplicationContext().getBean(KieRepositoryService.class);
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
this.userConnectedService = AppContext.getApplicationContext().getBean(UserConnectedService.class);
dialogPerso.getClose().setVisible(false);
MemoryBuffer fileBuffer = new MemoryBuffer();
importExcel=new Upload(fileBuffer);
importExcel.setDropLabel(new Span("drag and Drop Excel file here"));
importExcel.setClassName("menu-upload");
importExcel.setId("exampleupload");
dialogPerso.getBar().add(importExcel);
importExcel.addSucceededListener(succeededEvent -> {
if(!succeededEvent.getFileName().contains("xlsx")){
Notification.show("The file is incompatible, it must be in xlsx format");
}else {
try {
List<HashMap<String, Object>> objects= excelService.importExcel(fileBuffer.getInputStream());
if(objects!=null&&objects.size()>0){
if(objects.get(0).values().size()!=assetEdit.getColumns().size()){
Notification.show("Unable to add columns with the excel import for the moment");
}else {
remove(assetEdit);
assetEdit = new AssetEdit(objects);
add(assetEdit);
kieRepositoryService.updateAssetSource(config.getKiewbUrl(),
userConnectedService.getUserConnected().getUserName(),
userConnectedService.getUserConnected().getUserPassword(),
userConnectedService.getSpace(),
userConnectedService.getProject(),
userConnectedService.getAsset(),objects);
}
}else {
Notification.show("illegible or empty document");
}
} catch (IOException e) {
e.printStackTrace();
Notification.show("The file is incompatible, it must be in xlsx format");
}
}
});
importExcel.addFailedListener(failedEvent -> {
Notification.show("Error in the upload, please start again with another file");
});
FileDownloadWrapper fileDownloadWrapper=new FileDownloadWrapper(
new StreamResource("fsdfs.xlsx",
()->excelService.exportExcel(nameTemplate)));
exportExcel=new Button("Export excel");
fileDownloadWrapper.wrapComponent(exportExcel);
exportExcel.setClassName("menu-button-asset-edit");
dialogPerso.getBar().add(fileDownloadWrapper);
title=new Label(nameTemplate);
title.setClassName("creation-runtime-title");
add(title);
assetEdit=new AssetEdit();
add(assetEdit);
}
}

View file

@ -15,6 +15,7 @@ import org.chtijbug.drools.console.service.UserConnectedService;
import org.chtijbug.drools.console.service.model.UserConnected;
import org.chtijbug.drools.console.service.model.kie.KieConfigurationData;
import org.chtijbug.drools.console.service.util.AppContext;
import org.chtijbug.drools.console.vaadinComponent.ComponentPerso.DialogPerso;
import org.chtijbug.drools.console.vaadinComponent.componentView.AssetEdit;
import org.chtijbug.drools.console.vaadinComponent.leftMenu.Action.TemplatesAction;
import org.chtijbug.guvnor.server.jaxrs.jaxb.Asset;
@ -37,8 +38,6 @@ public class TemplateView extends VerticalLayout {
private ListDataProvider<Asset> dataProvider;
private ComboBox<PlatformProjectResponse> spaceSelection;
private Grid<Asset> assetListGrid;
private TextField searchTemplate;
@ -59,14 +58,6 @@ public class TemplateView extends VerticalLayout {
this.userConnected = userConnectedService.getUserConnected();
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
spaceSelection = new ComboBox("Project", userConnected.getProjectResponses());
spaceSelection.setItemLabelGenerator(PlatformProjectResponse::getName);
spaceSelection.addValueChangeListener(valueChangeEvent -> {
setDataProvider();
});
add(spaceSelection);
assetListGrid = new Grid();
assetListGrid.setClassName("templates-grid-perso");
assetListGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
@ -89,8 +80,8 @@ public class TemplateView extends VerticalLayout {
});
}
public void setDataProvider(){
PlatformProjectResponse response = (PlatformProjectResponse) spaceSelection.getValue();
public void setDataProvider(ComboBox<PlatformProjectResponse> spaceSelection){
PlatformProjectResponse response = spaceSelection.getValue();
List<Asset> tmp = kieRepositoryService.getListAssets(config.getKiewbUrl(), userConnected.getUserName(), userConnected.getUserPassword(), response.getSpaceName(), response.getName());
List<Asset> result = new ArrayList<>();
for (Asset asset : tmp) {
@ -105,10 +96,10 @@ public class TemplateView extends VerticalLayout {
reinitFilter();
}
public void refreshList() {
public void refreshList(ComboBox<PlatformProjectResponse> spaceSelection) {
spaceSelection.setItems(userConnected.getProjectResponses());
}
public void edit(){
public void edit(ComboBox<PlatformProjectResponse> spaceSelection){
Set<Asset> selectedElements = assetListGrid.getSelectedItems();
if (selectedElements.toArray().length > 0) {
String assetName = selectedElements.stream().findFirst().get().getTitle();
@ -117,9 +108,9 @@ public class TemplateView extends VerticalLayout {
userConnectedService.addAssetToSession(assetName);
userConnectedService.addProjectToSession(response.getName());
userConnectedService.addSpaceToSession(response.getSpaceName());
Dialog dialog=new Dialog();
DialogPerso dialog=new DialogPerso();
dialog.add(new AssetEdit());
dialog.add(new EditTemplateView(dialog,assetName));
dialog.open();
}
}
@ -140,6 +131,15 @@ public class TemplateView extends VerticalLayout {
}
return columnPredicate;
}
public UserConnectedService getUserConnectedService() {
return userConnectedService;
}
public void setUserConnectedService(UserConnectedService userConnectedService) {
this.userConnectedService = userConnectedService;
}
public void duplicate(){}
public void reinitFilter(){

View file

@ -1,4 +1,24 @@
.assetEdit-content{
width: 77vw!important;
height: 34vw;
}
.menu-upload{
background: transparent;
/* width: 100%; */
font-size: 1vw;
margin: 0px;
margin-left: 10px;
height: 4vw;
color: rgb(0,0,0,0.4);
border-radius: 0px;
}
.menu-button-asset-edit {
background: transparent;
/* width: 100%; */
font-size: 1vw;
margin: 0.5vw;
height: 3vw;
color: rgb(0,0,0,0.4);
border-radius: 0px;
cursor: pointer;
}

View file

@ -10,3 +10,36 @@
</style>
</template>
</dom-module>
<dom-module id="other" theme-for="vaadin-upload">
<template>
<style>
[part="upload-button"]{
color:rgb(0,0,0,0.4)!important;
}
</style>
</template>
</dom-module>
<dom-module id="my-file-download" theme-for="file-download-wrapper">
<template>
<style>
:host {
--my-color-exceptionnel:rgb(0,0,0,0.4);
}
</style>
</template>
</dom-module>
<dom-module id="button-link" theme-for="vaadin-button">
<template>
<style>
:host(.menu-button-asset-edit){
color:var(--my-color-exceptionnel, rgb(0,0,0,0.4));
}
</style>
</template>
</dom-module>

View file

@ -26,3 +26,5 @@ jenkins.group=EPO
spring.data.mongodb.database=businessProxyDB
spring.data.mongodb.host=localhost:27017
spring.servlet.multipart.enabled=false