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

@ -43,7 +43,6 @@ public class CalculatedAttribute {
public void setClassName(String className) {
this.className = className;
new Boolean(booleanValue).toString();
}
public String getKey() {

View file

@ -195,8 +195,9 @@ public class GenericResource {
Method traceMethod = foundClass.getMethod("logTrace", String.class);
if (traceMethod != null) {
jsonInString = mapper.writeValueAsString(chtijbutObjectResponse.getSessionLogging());
traceMethod.invoke(input, jsonInString);
}
traceMethod.invoke(input, jsonInString);
} catch (Exception e) {
}

View file

@ -43,7 +43,7 @@ public class SftpServerService {
public void initServer() throws IOException {
if (System.getProperty("org.chtijbug.server.sftpPort") != null) {
try {
port = Integer.valueOf(System.getProperty("org.chtijbug.server.sftpPort")).intValue();
port = Integer.valueOf(System.getProperty("org.chtijbug.server.sftpPort"));
} catch (NumberFormatException e) {
port = 9080;
}

View file

@ -311,13 +311,22 @@ public class PackageResource {
private org.uberfire.java.nio.file.Path getDirectoryElementPath(DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream, String assetName) {
for (org.uberfire.java.nio.file.Path elementPath : directoryStream) {
if (org.uberfire.java.nio.file.Files.isDirectory(elementPath)) {
DirectoryStream<org.uberfire.java.nio.file.Path> adirectoryStream = ioService.newDirectoryStream(elementPath);
if (elementPath.getFileName().toString().equals(assetName)) {
return elementPath;
}
org.uberfire.java.nio.file.Path foundElementPath = getDirectoryElementPath(adirectoryStream, assetName);
if (foundElementPath != null) {
return foundElementPath;
DirectoryStream<org.uberfire.java.nio.file.Path> adirectoryStream=null;
try {
adirectoryStream = ioService.newDirectoryStream(elementPath);
if (elementPath.getFileName().toString().equals(assetName)) {
return elementPath;
}
org.uberfire.java.nio.file.Path foundElementPath = getDirectoryElementPath(adirectoryStream, assetName);
if (foundElementPath != null) {
return foundElementPath;
}
}catch (Exception e){
}finally {
if (adirectoryStream!= null){
adirectoryStream.close();
}
}
}
}
@ -390,17 +399,31 @@ public class PackageResource {
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("projectName") String projectName, Asset asset) {
try {
WorkspaceProject project = getProject(organizationalUnitName, projectName);
org.uberfire.backend.vfs.Path rootPath = project.getRootPath();
org.uberfire.java.nio.file.Path nioPathDirectory = Paths.get(rootPath.toURI());
DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream = ioService.newDirectoryStream(nioPathDirectory);
if (project!= null) {
org.uberfire.backend.vfs.Path rootPath = project.getRootPath();
org.uberfire.java.nio.file.Path nioPathDirectory = Paths.get(rootPath.toURI());
DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream=null;
try {
directoryStream = ioService.newDirectoryStream(nioPathDirectory);
org.uberfire.java.nio.file.Path directoryWhereCreateAsset = getDirectoryElementPath(directoryStream, asset.getTitle());
if (directoryWhereCreateAsset!= null) {
final org.uberfire.java.nio.file.Path nioPath = Paths.get(directoryWhereCreateAsset.toUri());
if (ioService.exists(nioPath)) {
throw new FileAlreadyExistsException(nioPath.toString());
}
CommentedOption commentedOption = new CommentedOption(asset.getComment());
ioService.write(nioPath, asset.getContent().getBytes(), commentedOption);
}
}catch (Exception e){
}finally {
if (directoryStream!= null){
directoryStream.close();
}
}
org.uberfire.java.nio.file.Path directoryWhereCreateAsset = getDirectoryElementPath(directoryStream, asset.getTitle());
final org.uberfire.java.nio.file.Path nioPath = Paths.get(directoryWhereCreateAsset.toUri());
if (ioService.exists(nioPath)) {
throw new FileAlreadyExistsException(nioPath.toString());
}
CommentedOption commentedOption = new CommentedOption(asset.getComment());
ioService.write(nioPath, asset.getContent().getBytes(), commentedOption);
} catch (Exception e) {
throw new WebApplicationException(e);
}
@ -420,22 +443,26 @@ public class PackageResource {
WorkspaceProject project = getProject(organizationalUnitName, projectName);
if (project != null) {
// Optional<Branch> rr = project.getRepository().getBranch("ee");
// org.uberfire.backend.vfs.Path tata = rr.get().getPath();
// Optional<Branch> rr = project.getRepository().getBranch("ee");
// org.uberfire.backend.vfs.Path tata = rr.get().getPath();
org.uberfire.backend.vfs.Path rootPath = project.getRootPath();
org.uberfire.java.nio.file.Path nioPath = Paths.get(rootPath.toURI());
DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream = ioService.newDirectoryStream(nioPath);
org.uberfire.java.nio.file.Path elementToUpdate = getFileElementPath(directoryStream, assetName);
File fileToUpdate = elementToUpdate.toFile();
if (fileToUpdate.isFile()) {
content = content.replace("\"", "");
ioService.write(elementToUpdate, content);
// FileOutputStream fileOutputStream = new FileOutputStream(fileToUpdate);
// fileOutputStream.write(content.getBytes());
// fileOutputStream.close();
}
if (elementToUpdate != null) {
File fileToUpdate = elementToUpdate.toFile();
if (fileToUpdate.isFile()) {
content = content.replace("\"", "");
ioService.write(elementToUpdate, content);
// FileOutputStream fileOutputStream = new FileOutputStream(fileToUpdate);
// fileOutputStream.write(content.getBytes());
// fileOutputStream.close();
}
}
}else{
throw new WebApplicationException("Asset not found " + assetName);
}
} catch (RuntimeException e) {
throw new WebApplicationException(e);

View file

@ -63,7 +63,7 @@ public class DroolsFactObjectFactory {
}
return createFactObject;
} catch (Exception e) {
logger.error("Not possible to introspect {} for reason {}", o, e);
logger.error("Not possible to introspect {} for reason {}", o, e.getMessage(),e);
throw Throwables.propagate(e);
} finally {
logger.debug("<< createFactObject", createFactObject);

View file

@ -15,7 +15,6 @@
*/
package org.chtijbug.drools.runtime;
import org.chtijbug.drools.runtime.impl.RuleBaseCommandSingleton;
import org.chtijbug.drools.runtime.impl.RuleBaseSingleton;
import org.chtijbug.drools.runtime.listener.HistoryListener;
import org.chtijbug.drools.runtime.resource.FileKnowledgeResource;
@ -34,17 +33,7 @@ public abstract class RuleBaseBuilder {
*/
private static Logger logger = LoggerFactory.getLogger(RuleBaseBuilder.class);
public static RuleBasePackage createRemoteStandardRestBasePackage(String containerId, String url,String username,String password) throws DroolsChtijbugException {
logger.debug(">> createWorkbenchRuleBasePackage()");
RuleBaseCommandSingleton newRuleBasePackage = new RuleBaseCommandSingleton(RuleBaseSingleton.DEFAULT_RULE_THRESHOLD,containerId,url,username,password);
try {
newRuleBasePackage.connectKBase();
//_____ Returning the result
return newRuleBasePackage;
} finally {
logger.debug("<< createWorkbenchRuleBasePackage", newRuleBasePackage);
}
}
public static RuleBasePackage createWorkbenchRuleBasePackage(Long ruleBaseId, HistoryListener historyListener, String groupId, String artifactId, String version, String workbenchUrl, String username, String password) throws DroolsChtijbugException {

View file

@ -1,221 +0,0 @@
package org.chtijbug.drools.runtime.impl;
import org.chtijbug.drools.common.reflection.ReflectionUtils;
import org.chtijbug.drools.entity.DroolsFactObject;
import org.chtijbug.drools.entity.DroolsRuleObject;
import org.chtijbug.drools.entity.history.HistoryContainer;
import org.chtijbug.drools.runtime.DroolsChtijbugException;
import org.chtijbug.drools.runtime.RuleBaseSession;
import org.kie.api.KieServices;
import org.kie.api.command.BatchExecutionCommand;
import org.kie.api.command.Command;
import org.kie.api.command.KieCommands;
import org.kie.api.runtime.ExecutionResults;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.ObjectFilter;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.api.runtime.process.WorkItemHandler;
import org.kie.server.api.model.ServiceResponse;
import org.kie.server.client.KieServicesClient;
import org.kie.server.client.RuleServicesClient;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Created by nheron on 07/06/2016.
*/
public class RuleBaseCommandSession implements RuleBaseSession {
private List<Command<?>> commands = new ArrayList<Command<?>>();
private KieCommands commandsFactory = KieServices.Factory.get().getCommands();
private int maxNumberRuleToExecute = 2000;
private KieServicesClient kieServicesClient;
private String containerId;
public RuleBaseCommandSession(int maxNumberRuleToExecute,KieServicesClient kieServicesClient,String containerId) {
this.maxNumberRuleToExecute = maxNumberRuleToExecute;
this.kieServicesClient=kieServicesClient;
this.containerId = containerId;
}
@Override
public void insertObject(Object newObject) {
commands.add(commandsFactory.newInsert(newObject, newObject.toString()));
}
@Override
public void insertByReflection(Object newObject) throws DroolsChtijbugException {
if (newObject.getClass().getPackage().getName().startsWith("java.")) {
return;
}
//____ Then foreach getters insert item by reflection
for (Method method : newObject.getClass().getMethods()) {
//____ only manage getters
if (!ReflectionUtils.IsGetter(method)) {
continue;
}
Object getterValue;
try {
getterValue = method.invoke(newObject, (Object[]) null);
} catch (Exception e) {
throw new DroolsChtijbugException(DroolsChtijbugException.insertByReflection, "getterValue = method.invoke(newObject, (Object[]) null);", e);
}
if (getterValue == null)
continue;
//____ If returned value is not a collection, insert it in the ksession
if (!(getterValue instanceof Iterable)) {
this.insertByReflection(getterValue);
} else {
Iterable<?> iterable = (Iterable) getterValue;
for (Object item : iterable) {
this.insertByReflection(item);
}
}
}
this.insertObject(newObject);
}
@Override
public void setGlobal(String identifier, Object value) {
commands.add(commandsFactory.newSetGlobal(identifier, value));
}
@Override
public void updateObject(Object updatedObject) {
// Not Possible
}
@Override
public void retractObject(Object oldObject) {
// Not Possible
}
@Override
public void fireAllRules() throws DroolsChtijbugException {
commands.add(commandsFactory.newFireAllRules(maxNumberRuleToExecute));
}
@Override
public Object fireAllRulesAndStartProcess(Object inputObject, String processName) throws DroolsChtijbugException {
Object outputObject=null;
if (inputObject != null) {
//this.insertObject(inputObject);
this.insertByReflection(inputObject);
}
if (processName != null && processName.length() > 0) {
this.startProcess(processName);
}
this.fireAllRules();
commands.add(commandsFactory.newGetObjects(inputObject.getClass().getName()));
RuleServicesClient ruleClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
BatchExecutionCommand batchCommand = commandsFactory.newBatchExecution(commands);
ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(this.containerId, batchCommand);
if (response.equals(ServiceResponse.ResponseType.SUCCESS)){
ExecutionResults actualData = response.getResult();
Collection<String> identifiers = actualData.getIdentifiers();
for (String id : identifiers){
outputObject=actualData.getValue(id);
}
}
return outputObject;
}
@Override
public Object fireAllRulesAndStartProcessWithParam(Object inputObject, String processName) throws DroolsChtijbugException {
//commands.add(commandsFactory.newFireAllRules(maxNumberRuleToExecute));
return this.fireAllRulesAndStartProcess(inputObject,processName);
}
@Override
public void startProcess(String processName) {
commands.add(commandsFactory.newStartProcess(processName));
}
@Override
public void dispose() {
}
@Override
public HistoryContainer getHistoryContainer() {
return null;
}
@Override
public String getHistoryContainerXML() {
return null;
}
@Override
public Collection<DroolsFactObject> listLastVersionObjects() {
return null;
}
@Override
public String listLastVersionObjectsXML() {
return null;
}
@Override
public Collection<DroolsRuleObject> listRules() {
return null;
}
@Override
public int getNumberRulesExecuted() {
return 0;
}
@Override
public Long getSessionId() {
return null;
}
@Override
public Long getRuleBaseID() {
return null;
}
@Override
public KieSession getKnowledgeSession() {
return null;
}
@Override
public Collection<? extends Object> getObjects(ObjectFilter objectFilter) {
return null;
}
@Override
public void completeWorkItem(long processId, Map<String, Object> vars) {
commands.add(commandsFactory.newCompleteWorkItem(processId, vars));
}
@Override
public void abortWorkItem(long processId) {
commands.add(commandsFactory.newAbortWorkItem(processId));
}
@Override
public void registerWorkItemHandler(String workItemName, WorkItemHandler workItemHandler) {
commands.add(commandsFactory.newRegisterWorkItemHandlerCommand(workItemHandler, workItemName));
}
@Override
public ProcessInstance startProcess(String processName, Map<String, Object> vars) {
commands.add(commandsFactory.newStartProcess(processName, vars));
return null;
}
public List<Command<?>> getCommands() {
return commands;
}
}

View file

@ -1,127 +0,0 @@
package org.chtijbug.drools.runtime.impl;
import org.chtijbug.drools.entity.history.EventCounter;
import org.chtijbug.drools.runtime.DroolsChtijbugException;
import org.chtijbug.drools.runtime.RuleBasePackage;
import org.chtijbug.drools.runtime.RuleBaseSession;
import org.chtijbug.drools.runtime.listener.HistoryListener;
import org.kie.server.api.marshalling.MarshallingFormat;
import org.kie.server.client.KieServicesClient;
import org.kie.server.client.KieServicesConfiguration;
import org.kie.server.client.KieServicesFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Semaphore;
/**
* Created by nheron on 07/06/2016.
*/
public class RuleBaseCommandSingleton implements RuleBasePackage {
/**
* default rule threshold
*/
public static int DEFAULT_RULE_THRESHOLD = 2000;
/**
* Class Logger
*/
private static Logger logger = LoggerFactory.getLogger(RuleBaseCommandSingleton.class);
/**
* unique ID of the RuleBase in the JVM
*/
protected EventCounter eventCounter = EventCounter.newCounter();
protected EventCounter sessionCounter = EventCounter.newCounter();
private int maxNumberRuleToExecute = DEFAULT_RULE_THRESHOLD;
/**
* Semaphore used to void concurrent access to the singleton
*/
private Semaphore lockKbase = new Semaphore(1);
/**
* History Listener
*/
private String containerId;
private String url;
private String username;
private String password;
private KieServicesClient kieServicesClient;
public RuleBaseCommandSingleton(int maxNumberRuleToExecute) {
this.maxNumberRuleToExecute = maxNumberRuleToExecute;
}
public RuleBaseCommandSingleton(int defaultRuleThreshold, String containerId,String url, String username, String password) {
this(defaultRuleThreshold);
this.containerId=containerId;
this.url=url;
this.username=username;
this.password=password;
}
@Override
public RuleBaseSession createRuleBaseSession() throws DroolsChtijbugException {
logger.debug(">>createRuleBaseSession");
try {
//____ Creating new Rule Base Session using default rule threshold
return this.createRuleBaseSession(this.maxNumberRuleToExecute);
} finally {
logger.debug("<<createRuleBaseSession");
}
}
@Override
public RuleBaseSession createRuleBaseSession(int maxNumberRulesToExecute) throws DroolsChtijbugException {
return this.createRuleBaseSession(maxNumberRulesToExecute, null);
}
@Override
public RuleBaseSession createRuleBaseSession(int maxNumberRulesToExecute, HistoryListener sessionHistoryListener) throws DroolsChtijbugException {
logger.debug(">>createRuleBaseSession", maxNumberRulesToExecute);
RuleBaseSession newRuleBaseSession = null;
try {
//_____ Wrapping the knowledge Session
newRuleBaseSession = new RuleBaseCommandSession(maxNumberRulesToExecute,this.kieServicesClient,this.containerId);
//_____ Release semaphore
lockKbase.release();
return newRuleBaseSession;
} finally {
logger.debug("<<createRuleBaseSession", newRuleBaseSession);
}
}
@Override
public RuleBaseSession createRuleBaseSession(int maxNumberRulesToExecute, HistoryListener sessionHistoryListener, String sessionName) throws DroolsChtijbugException {
return this.createRuleBaseSession(maxNumberRulesToExecute, sessionHistoryListener);
}
@Override
public void loadKBase(String version) throws DroolsChtijbugException {
//
}
@Override
public HistoryListener getHistoryListener() {
return null;
}
@Override
public Long getRuleBaseID() {
return null;
}
@Override
public void dispose() {
}
public void connectKBase() {
KieServicesConfiguration config;
config = KieServicesFactory.newRestConfiguration(url, username, password);
MarshallingFormat marshallingFormat = MarshallingFormat.XSTREAM;
config.setMarshallingFormat(marshallingFormat);
this.kieServicesClient = KieServicesFactory.newKieServicesClient(config);
}
}

View file

@ -20,7 +20,7 @@ public enum FactType {
public static FactType getEnum(String factType) {
for (FactType type : FactType.values()) {
if (type.name().equals(type))
if (type.name().equals(factType))
return type;
}
return null;