Work after Sonarcloud

This commit is contained in:
Nicolas Héron 2020-06-01 16:34:55 +02:00
commit 0a97629aa5
25 changed files with 256 additions and 503 deletions

View file

@ -32,7 +32,7 @@ public class DecisionTableExcelService {
private String assetContent;
public DecisionTableExcelService(){
public DecisionTableExcelService() {
this.kieRepositoryService = AppContext.getApplicationContext().getBean(KieRepositoryService.class);
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
this.userConnectedService = AppContext.getApplicationContext().getBean(UserConnectedService.class);
@ -48,37 +48,43 @@ public class DecisionTableExcelService {
return assetContent;
}
public List<HashMap<String,Object>> importExcel(InputStream inputStream) throws IOException {
public List<HashMap<String, Object>> importExcel(InputStream inputStream) throws IOException {
Workbook workbook = null;
List<HashMap<String, Object>> result = null;
try {
workbook = WorkbookFactory.create(inputStream);
result = new ArrayList<>();
DataFormatter dataFormatter = new DataFormatter();
for (Sheet sheet : workbook) {
for (Row row : sheet) {
Workbook workbook= WorkbookFactory.create(inputStream);
if (row.getRowNum() != 0) {
DataFormatter dataFormatter = new DataFormatter();
HashMap<String, Object> tmp = new HashMap<>();
result.add(tmp);
List<HashMap<String,Object>> result=new ArrayList<>();
for (Cell cell : row) {
String cellValue = dataFormatter.formatCellValue(cell);
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);
Integer numColumn = cell.getColumnIndex();
Cell title = sheet.getRow(0).getCell(numColumn);
tmp.put(dataFormatter.formatCellValue(title), cellValue);
}
}
}
}
} catch (IOException e) {
throw e;
} finally {
if (workbook != null) {
workbook.close();
}
}
return result;
}
public ByteArrayInputStream exportExcel(String nameTemplate) {
public ByteArrayInputStream exportExcel(String nameTemplate) {
//Récupération des objets JAVA
@ -89,11 +95,10 @@ public class DecisionTableExcelService {
userConnectedService.getProject(),
userConnectedService.getAsset());
GuidedDecisionTable52 model = GuidedDTXMLPersistence.getInstance().unmarshal(assetContent);
Workbook workbook = null;
try {
workbook = new XSSFWorkbook();
DecisionTable decisionTable = new DecisionTable(model);
Workbook workbook = new XSSFWorkbook();
CreationHelper createHelper = workbook.getCreationHelper();
Sheet sheet = workbook.createSheet(nameTemplate);
@ -108,9 +113,9 @@ public class DecisionTableExcelService {
if (decisionTable.getRows() != null && decisionTable.getRows().size() != 0) {
int columnIndex = 0;
int j=0;
int j = 0;
for (ColumnDefinition columnDefinition : decisionTable.getColumnDefinitionList()) {
if (columnDefinition.isHideColumn()==false){
if (columnDefinition.isHideColumn() == false) {
Cell cell = headerRow.createCell(j);
cell.setCellValue(columnDefinition.getHeader());
cell.setCellStyle(headerCellStyle);
@ -123,16 +128,16 @@ public class DecisionTableExcelService {
for (int i = 0; i < decisionTable.getRows().size(); i++) {
org.chtijbug.drools.console.vaadinComponent.componentView.service.dtmodel.Row row = decisionTable.getRows().get(i);
int k = 0;
int jj=0;
int jj = 0;
Row r = sheet.createRow(rowIndex);
for (ColumnDefinition columnDefinition : decisionTable.getColumnDefinitionList()) {
if (columnDefinition.isHideColumn()==false) {
if (columnDefinition.isHideColumn() == false) {
Cell cell = r.createCell(k);
cell.setCellValue(row.getRowElements().get(jj).getValue());
cell.setCellStyle(headerCellStyle);
k++;
}
jj++;
jj++;
}
rowIndex++;
}
@ -140,7 +145,7 @@ public class DecisionTableExcelService {
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
FileOutputStream fileOutputStream=new FileOutputStream(tmpDir+"/"+nameTemplate+".xlsx");
FileOutputStream fileOutputStream = new FileOutputStream(tmpDir + "/" + nameTemplate + ".xlsx");
workbook.write(fileOutputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
@ -165,6 +170,14 @@ public class DecisionTableExcelService {
} catch (GuidedException e) {
e.printStackTrace();
} finally {
if (workbook != null) {
try {
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}

View file

@ -31,7 +31,7 @@ public class GuidedRuleTemplateExcelService {
private String assetContent;
public GuidedRuleTemplateExcelService(){
public GuidedRuleTemplateExcelService() {
this.kieRepositoryService = AppContext.getApplicationContext().getBean(KieRepositoryService.class);
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
this.userConnectedService = AppContext.getApplicationContext().getBean(UserConnectedService.class);
@ -48,37 +48,38 @@ public class GuidedRuleTemplateExcelService {
return assetContent;
}
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);
public List<HashMap<String, Object>> importExcel(InputStream inputStream) throws IOException {
List<HashMap<String, Object>> result = null;
Workbook workbook = null;
try {
workbook = WorkbookFactory.create(inputStream);
DataFormatter dataFormatter = new DataFormatter();
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);
}
}
}
}
} catch (IOException e) {
throw e;
} finally {
if (workbook != null) {
workbook.close();
}
}
return result;
}
public ByteArrayInputStream exportExcel(String nameTemplate){
public ByteArrayInputStream exportExcel(String nameTemplate) {
//Récupération des objets JAVA
@ -117,24 +118,24 @@ public class GuidedRuleTemplateExcelService {
CellStyle headerCellStyle = workbook.createCellStyle();
headerCellStyle.setFont(headerFont);
Row headerRow=sheet.createRow(0);
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);
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 rowIndex = 1;
for (HashMap<String, Object> t : rows) {
int columnIndexTmp=0;
Row r=sheet.createRow(rowIndex);
int columnIndexTmp = 0;
Row r = sheet.createRow(rowIndex);
for (Map.Entry<String, Object> tmp : t.entrySet()) {
Cell cell=r.createCell(columnIndexTmp);
Cell cell = r.createCell(columnIndexTmp);
cell.setCellValue(String.valueOf(tmp.getValue()));
cell.setCellStyle(headerCellStyle);
columnIndexTmp++;
@ -144,7 +145,7 @@ public class GuidedRuleTemplateExcelService {
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
FileOutputStream fileOutputStream=new FileOutputStream(tmpDir+"/"+nameTemplate+".xlsx");
FileOutputStream fileOutputStream = new FileOutputStream(tmpDir + "/" + nameTemplate + ".xlsx");
workbook.write(fileOutputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();

View file

@ -23,7 +23,7 @@ import java.util.Map;
public class JenkinsService {
JenkinsServer jenkins = null;
public void createJobForRepo(String jenkinsServerUrl, String username, String password, String viewName, String groupId, String artifactId, String pomXml, String nexusName, String nexusUrl, String jdkVersion) throws URISyntaxException, IOException {
public void createJobForRepo(String jenkinsServerUrl, String username, String password, String viewName, String groupId, String artifactId, String pomXml, String nexusName, String nexusUrl, String jdkVersion) throws URISyntaxException, IOException, InterruptedException {
GitLabConfigurationData configGitLab = AppContext.getApplicationContext().getBean(GitLabConfigurationData.class);
JenkinsConfigurationData jenkinsConfigurationData = AppContext.getApplicationContext().getBean(JenkinsConfigurationData.class);
@ -57,9 +57,9 @@ public class JenkinsService {
} else {
synchronized (this) {
try {
Thread.currentThread().wait(1000);
this.wait(1000);
} catch (InterruptedException e) {
e.printStackTrace();
throw e;
}
}
}

View file

@ -25,6 +25,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static com.google.common.base.Throwables.propagate;
@Service
@DependsOn("applicationContext")
public class ProjectPersistService {
@ -229,10 +231,12 @@ public class ProjectPersistService {
} else if ("ACCEPTED".equals(jobStatus.getStatus())
|| ("APPROVED".equals(jobStatus.getStatus()))) {
try {
workOnGoingView.addRow("JobID=" + jobID + " not yet finished", ui);
Thread.sleep(1000);
synchronized (this) {
workOnGoingView.addRow("JobID=" + jobID + " not yet finished", ui);
this.wait(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
propagate(e);
}
} /*else if("RESOURCE_NOT_EXIST".equals(jobStatus.getStatus())||
"SERVER_ERROR".equals(jobStatus.getStatus())||

View file

@ -67,7 +67,7 @@ public class AssociateProjectKie extends VerticalLayout {
});
gridRuntime.addSelectionListener(selectionEvent -> {
if (selectionEvent.getFirstSelectedItem() != null && selectionEvent.getFirstSelectedItem().isPresent()) {
if ( selectionEvent.getFirstSelectedItem().isPresent()) {
associer.setEnabled(true);
} else {

View file

@ -91,7 +91,7 @@ public class ColumnDefinition {
this.header = actionSetFieldCol52.getHeader();
if (actionSetFieldCol52.getDefaultValue() != null) {
DTCellValue52 defaultValue = actionSetFieldCol52.getDefaultValue();
if (!(DataType.TYPE_STRING.equals(defaultValue.getDataType()) && defaultValue.getStringValue().isEmpty())) {
if (!(DataType.DataTypes.STRING.equals(defaultValue.getDataType()) && defaultValue.getStringValue().isEmpty())) {
this.hasDefaultValue = true;
this.defaultValue = getValue(actionSetFieldCol52.getDefaultValue());
}
@ -107,7 +107,7 @@ public class ColumnDefinition {
this.header = actionInsertFact52.getHeader();
if (actionInsertFact52.getDefaultValue() != null) {
DTCellValue52 defaultValue = actionInsertFact52.getDefaultValue();
if (!(DataType.TYPE_STRING.equals(defaultValue.getDataType()) && defaultValue.getStringValue().isEmpty())) {
if (!(DataType.DataTypes.STRING.equals(defaultValue.getDataType()) && defaultValue.getStringValue().isEmpty())) {
this.hasDefaultValue = true;
this.defaultValue = getValue(actionInsertFact52.getDefaultValue());
}

View file

@ -41,7 +41,7 @@ public class GuidedException extends Exception {
}
public void setAttribute(String attribute) {
attribute = attribute;
this.attribute = attribute;
}
public String getValue() {

View file

@ -74,7 +74,7 @@ public class InformationStructure extends VerticalLayout {
List<RuntimePersist> runtimePersists=runtimeService.getRuntimeRepository().findAll();
actualiseKieServer(runtimePersists!=null?runtimePersists.size():0);
actualiseKieServer(runtimePersists.size());
numberKieWb=new Label(strKieWb+"0");
numberKieWb.setClassName("leftMenu-global-inforStructure-label");

View file

@ -10,6 +10,8 @@ import com.vaadin.flow.router.Route;
import com.vaadin.flow.shared.communication.PushMode;
import org.chtijbug.drools.console.vaadinComponent.Squelette.SqueletteComposant;
import java.util.Optional;
@Push(PushMode.AUTOMATIC)
@StyleSheet("css/accueil.css")
@HtmlImport("frontend://styles/shared-styles.html")
@ -22,7 +24,10 @@ public class AccueilView extends SqueletteComposant implements BeforeEnterObserv
if (getUserConnectedService().getUserConnected()==null) {
beforeEnterEvent.rerouteTo(LoginView.class);
UI.getCurrent().getUI().get().getPage().executeJavaScript("window.alert($0)", "Session expiré, veuillez-vous reconnecter");
Optional<UI> theUI = UI.getCurrent().getUI();
if (theUI.isPresent()) {
theUI.get().getPage().executeJavaScript("window.alert($0)", "Session expiré, veuillez-vous reconnecter");
}
}
}

View file

@ -172,7 +172,7 @@ public class DeploymentView extends VerticalLayout implements AddLog {
projectPersistGrid.addSelectionListener(selectionEvent -> {
if (selectionEvent.getFirstSelectedItem() != null && selectionEvent.getFirstSelectedItem().isPresent()) {
if (selectionEvent.getFirstSelectedItem().isPresent()) {
majAction(selectionEvent.getFirstSelectedItem().get());
} else {
getDeploymentAction().getAssociateKieServer().setEnabled(false);

View file

@ -4,7 +4,6 @@ import com.vaadin.flow.component.dependency.StyleSheet;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import org.chtijbug.drools.console.vaadinComponent.componentView.GridLogging;
import org.chtijbug.drools.console.vaadinComponent.componentView.GridRuntime;
import org.chtijbug.drools.console.vaadinComponent.leftMenu.Action.ActionLogging;
@StyleSheet("css/accueil.css")
@ -31,7 +30,7 @@ public class LoggingView extends VerticalLayout {
gridLogging.addSelectionListener(selectionEvent -> {
if(selectionEvent.getFirstSelectedItem()!=null&&selectionEvent.getFirstSelectedItem().isPresent()) {
if(selectionEvent.getFirstSelectedItem().isPresent()) {
actionLogging.getViewAction().setEnabled(true);
}else {
actionLogging.getViewAction().setEnabled(false);

View file

@ -2,7 +2,6 @@ package org.chtijbug.drools.console.view;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.dependency.StyleSheet;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
@ -16,12 +15,14 @@ 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;
import org.chtijbug.guvnor.server.jaxrs.model.PlatformProjectResponse;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@StyleSheet("css/accueil.css")
public class TemplateView extends VerticalLayout {
@ -102,16 +103,19 @@ public class TemplateView extends VerticalLayout {
public void edit(ComboBox<PlatformProjectResponse> spaceSelection){
Set<Asset> selectedElements = assetListGrid.getSelectedItems();
if (selectedElements.toArray().length > 0) {
String assetName = selectedElements.stream().findFirst().get().getTitle();
if (assetName != null) {
PlatformProjectResponse response = spaceSelection.getValue();
userConnectedService.addAssetToSession(assetName);
userConnectedService.addProjectToSession(response.getName());
userConnectedService.addSpaceToSession(response.getSpaceName());
DialogPerso dialog=new DialogPerso();
Optional<Asset> assetOptional = selectedElements.stream().findFirst();
if (assetOptional.isPresent()) {
String assetName = assetOptional.get().getTitle();
if (assetName != null) {
PlatformProjectResponse response = spaceSelection.getValue();
userConnectedService.addAssetToSession(assetName);
userConnectedService.addProjectToSession(response.getName());
userConnectedService.addSpaceToSession(response.getSpaceName());
DialogPerso dialog = new DialogPerso();
dialog.add(new EditTemplateView(dialog,assetName));
dialog.open();
dialog.add(new EditTemplateView(dialog, assetName));
dialog.open();
}
}
}
}

View file

@ -1,5 +1,5 @@
server.port=${port:8200}
kie-wb.baseurl=http://localhost:8080/kie-wb/rest
kie-wb.baseurl=http://localhost:18080/kie-wb/rest
kie-wb.mainwbintern=http://localhost:8080/kie-wb
kie-wb.mainwbextern=http://localhost:8080/kie-wb
kie-wb.username=admin