clean code and update to version 7.38.0 of drools
This commit is contained in:
parent
6c2d336cf1
commit
fd551f7af8
9 changed files with 85 additions and 118 deletions
|
|
@ -7,6 +7,8 @@ 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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -21,6 +23,8 @@ import java.util.Map;
|
|||
@DependsOn("applicationContext")
|
||||
public class GuidedRuleTemplateExcelService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GuidedRuleTemplateExcelService.class);
|
||||
|
||||
@Value("${adminConsole.tmpdir}")
|
||||
public String tmpDir;
|
||||
|
||||
|
|
@ -29,7 +33,6 @@ public class GuidedRuleTemplateExcelService {
|
|||
|
||||
private UserConnectedService userConnectedService;
|
||||
|
||||
private String assetContent;
|
||||
|
||||
public GuidedRuleTemplateExcelService() {
|
||||
this.kieRepositoryService = AppContext.getApplicationContext().getBean(KieRepositoryService.class);
|
||||
|
|
@ -39,20 +42,18 @@ public class GuidedRuleTemplateExcelService {
|
|||
}
|
||||
|
||||
public String getAssetContent() {
|
||||
assetContent = kieRepositoryService.getAssetSource(config.getKiewbUrl(),
|
||||
return kieRepositoryService.getAssetSource(config.getKiewbUrl(),
|
||||
userConnectedService.getUserConnected().getUserName(),
|
||||
userConnectedService.getUserConnected().getUserPassword(),
|
||||
userConnectedService.getSpace(),
|
||||
userConnectedService.getProject(),
|
||||
userConnectedService.getAsset());
|
||||
return assetContent;
|
||||
}
|
||||
|
||||
public List<HashMap<String, Object>> importExcel(InputStream inputStream) throws IOException {
|
||||
List<HashMap<String, Object>> result = null;
|
||||
Workbook workbook = null;
|
||||
try {
|
||||
workbook = WorkbookFactory.create(inputStream);
|
||||
|
||||
try (Workbook workbook = WorkbookFactory.create(inputStream)) {
|
||||
DataFormatter dataFormatter = new DataFormatter();
|
||||
result = new ArrayList<>();
|
||||
for (Sheet sheet : workbook) {
|
||||
|
|
@ -69,12 +70,6 @@ public class GuidedRuleTemplateExcelService {
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (workbook != null) {
|
||||
workbook.close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -83,12 +78,7 @@ public class GuidedRuleTemplateExcelService {
|
|||
|
||||
//Récupération des objets JAVA
|
||||
|
||||
String assetContent = kieRepositoryService.getAssetSource(config.getKiewbUrl(),
|
||||
userConnectedService.getUserConnected().getUserName(),
|
||||
userConnectedService.getUserConnected().getUserPassword(),
|
||||
userConnectedService.getSpace(),
|
||||
userConnectedService.getProject(),
|
||||
userConnectedService.getAsset());
|
||||
String assetContent = getAssetContent();
|
||||
|
||||
TemplateModel model = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(assetContent);
|
||||
InterpolationVariable[] variablesList = model.getInterpolationVariablesList();
|
||||
|
|
@ -106,67 +96,52 @@ public class GuidedRuleTemplateExcelService {
|
|||
k++;
|
||||
}
|
||||
}
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
Sheet sheet = workbook.createSheet(nameTemplate);
|
||||
|
||||
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());
|
||||
|
||||
Font headerFont = workbook.createFont();
|
||||
headerFont.setFontHeightInPoints((short) 12);
|
||||
headerFont.setColor(IndexedColors.BLACK.getIndex());
|
||||
CellStyle headerCellStyle = workbook.createCellStyle();
|
||||
headerCellStyle.setFont(headerFont);
|
||||
|
||||
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);
|
||||
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()));
|
||||
if (rows != null && !rows.isEmpty()) {
|
||||
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);
|
||||
columnIndexTmp++;
|
||||
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++;
|
||||
}
|
||||
rowIndex++;
|
||||
}
|
||||
}
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(tmpDir + "/" + nameTemplate + ".xlsx");
|
||||
workbook.write(fileOutputStream);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
workbook.write(bos);
|
||||
byte[] barray = bos.toByteArray();
|
||||
return new ByteArrayInputStream(barray);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("exportExcel", e);
|
||||
}
|
||||
byte[] barray = bos.toByteArray();
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(barray);
|
||||
|
||||
try {
|
||||
workbook.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return is;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import org.chtijbug.drools.proxy.persistence.repository.ContainerRuntimeReposito
|
|||
import org.chtijbug.drools.proxy.persistence.repository.ProjectRepository;
|
||||
import org.chtijbug.drools.proxy.persistence.repository.RuntimeRepository;
|
||||
import org.chtijbug.guvnor.server.jaxrs.model.PlatformProjectResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -24,14 +26,15 @@ import org.springframework.stereotype.Service;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@DependsOn("applicationContext")
|
||||
public class ProjectPersistService {
|
||||
|
||||
public static String PROJECT = "4";
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProjectPersistService.class);
|
||||
|
||||
private static String projectVariable = "4";
|
||||
|
||||
@Autowired
|
||||
private ProjectRepository projectRepository;
|
||||
|
|
@ -59,13 +62,8 @@ public class ProjectPersistService {
|
|||
|
||||
}
|
||||
|
||||
public static String getPROJECT() {
|
||||
return PROJECT;
|
||||
}
|
||||
|
||||
public static void setPROJECT(String PROJECT) {
|
||||
ProjectPersistService.PROJECT = PROJECT;
|
||||
}
|
||||
|
||||
|
||||
public void saveIfnotExist(List<PlatformProjectResponse> platformProjectResponses) {
|
||||
|
||||
|
|
@ -90,13 +88,13 @@ public class ProjectPersistService {
|
|||
}
|
||||
}
|
||||
|
||||
public HashMap<String, ProjectPersist> getProjectsSession() {
|
||||
return (HashMap<String, ProjectPersist>) VaadinSession.getCurrent().getAttribute(PROJECT);
|
||||
public Map<String, ProjectPersist> getProjectsSession() {
|
||||
return (Map<String, ProjectPersist>) VaadinSession.getCurrent().getAttribute(projectVariable);
|
||||
}
|
||||
|
||||
public void addProjectToSession(ProjectPersist projectPersist, boolean isModifiable) {
|
||||
|
||||
HashMap<String, ProjectPersist> projectPersists = getProjectsSession();
|
||||
Map<String, ProjectPersist> projectPersists = getProjectsSession();
|
||||
|
||||
if (projectPersists == null) {
|
||||
projectPersists = new HashMap<>();
|
||||
|
|
@ -112,7 +110,7 @@ public class ProjectPersistService {
|
|||
}
|
||||
}
|
||||
|
||||
VaadinSession.getCurrent().setAttribute(PROJECT, projectPersists);
|
||||
VaadinSession.getCurrent().setAttribute(projectVariable, projectPersists);
|
||||
}
|
||||
|
||||
public boolean associate(ProjectPersist projectPersist, List<RuntimePersist> runtimePersists) {
|
||||
|
|
@ -120,12 +118,8 @@ public class ProjectPersistService {
|
|||
projectPersist.setContainerID(projectPersist.getDeploymentName() + "-" + projectPersist.getProjectName());
|
||||
projectPersist.getServerNames().clear();
|
||||
for (RuntimePersist runtimePersist : runtimePersists) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
List<String> names = new ArrayList<>();
|
||||
names.add(runtimePersist.getServerName());
|
||||
List<ProjectPersist> projectPersists = projectRepository.findByServerNamesInAndDeploymentName(names, projectPersist.getDeploymentName());
|
||||
//if (projectPersists.size() != 0) {
|
||||
// return false;
|
||||
// }
|
||||
projectPersist.getServerNames().add(runtimePersist.getServerName());
|
||||
ContainerPojoPersist existingContainer = containerRepository.findByServerNameAndContainerId(runtimePersist.getServerName(), projectPersist.getContainerID());
|
||||
if (existingContainer == null) {
|
||||
|
|
@ -175,6 +169,7 @@ public class ProjectPersistService {
|
|||
UserConnected userConnected = userConnectedService.getUserConnected();
|
||||
|
||||
Thread thread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
JobStatus result = kieRepositoryService.buildProject(config.getKiewbUrl(), userConnected.getUserName(),
|
||||
|
|
@ -187,11 +182,10 @@ public class ProjectPersistService {
|
|||
|
||||
executeWrite(url, username, password, workOnGoingView, result.getJobId(), ui);
|
||||
|
||||
// ContainerPojoPersist toto = containerRepository.findByServerNameAndContainerId(projectPersist.getContainerID());
|
||||
for (String serverName : projectPersist.getServerNames()) {
|
||||
for (String serverName : projectPersist.getServerNames()) {
|
||||
|
||||
List<ContainerRuntimePojoPersist> existingContainers = containerRuntimeRepository.findByServerNameAndContainerId(serverName, projectPersist.getContainerID());
|
||||
if (existingContainers.size() > 0) {
|
||||
if (!existingContainers.isEmpty()) {
|
||||
for (ContainerRuntimePojoPersist containerRuntimePojoPersist : existingContainers) {
|
||||
containerRuntimePojoPersist.setStatus(ContainerRuntimePojoPersist.STATUS.TODEPLOY.name());
|
||||
containerRuntimeRepository.save(containerRuntimePojoPersist);
|
||||
|
|
@ -236,13 +230,10 @@ public class ProjectPersistService {
|
|||
this.wait(1000);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
propagate(e);
|
||||
logger.error("executeWrite",e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} /*else if("RESOURCE_NOT_EXIST".equals(jobStatus.getStatus())||
|
||||
"SERVER_ERROR".equals(jobStatus.getStatus())||
|
||||
"FAIL".equals(jobStatus.getStatus())){
|
||||
isJobDone = "ERROR";
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue