Arefactoring drools admin console
navigator start asset update for rule Template
This commit is contained in:
parent
68d39cf456
commit
45f214dbd0
8 changed files with 453 additions and 148 deletions
|
|
@ -38,6 +38,22 @@
|
|||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.pymmasoftware.jbpm</groupId>
|
||||
<artifactId>drools-framework-kie-wb-rest-pojo</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.drools</groupId>
|
||||
<artifactId>drools-workbench-models-guided-template</artifactId>
|
||||
<version>${jbpm.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.uberfire</groupId>
|
||||
<artifactId>uberfire-commons</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.offbytwo.jenkins</groupId>
|
||||
<artifactId>jenkins-client</artifactId>
|
||||
|
|
@ -105,6 +121,30 @@
|
|||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>2.9.4</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-jaxb-annotations</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-jaxb-annotations</artifactId>
|
||||
<version>2.9.4</version>
|
||||
</dependency>
|
||||
<!--dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@ package org.chtijbug.drools.console;
|
|||
import com.vaadin.annotations.PreserveOnRefresh;
|
||||
import com.vaadin.annotations.Push;
|
||||
import com.vaadin.annotations.Theme;
|
||||
import com.vaadin.event.FieldEvents;
|
||||
import com.vaadin.navigator.Navigator;
|
||||
import com.vaadin.server.VaadinRequest;
|
||||
import com.vaadin.spring.annotation.SpringUI;
|
||||
import com.vaadin.ui.*;
|
||||
import com.vaadin.ui.MenuBar;
|
||||
import com.vaadin.ui.UI;
|
||||
import org.chtijbug.drools.console.service.JenkinsService;
|
||||
import org.chtijbug.drools.console.service.KieRepositoryService;
|
||||
import org.chtijbug.drools.console.service.KieServerRepositoryService;
|
||||
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.view.DeploymentView;
|
||||
import org.chtijbug.drools.console.view.TableLikeArtefactView;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Push
|
||||
|
|
@ -36,59 +36,41 @@ public class DroolsAdminConsoleMainView extends UI {
|
|||
private KieServerRepositoryService kieServerRepositoryService;
|
||||
@Autowired
|
||||
private JenkinsService jenkinsService;
|
||||
private TextField userNameTextField;
|
||||
private PasswordField userpasswdTextField;
|
||||
|
||||
final private Navigator navigator = new Navigator(this, this);
|
||||
|
||||
public DroolsAdminConsoleMainView() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(VaadinRequest request) {
|
||||
final VerticalLayout layout = new VerticalLayout();
|
||||
KieConfigurationData configKie = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
|
||||
// GitLabConfigurationData configGitLab = AppContext.getApplicationContext().getBean(GitLabConfigurationData.class);
|
||||
// JenkinsConfigurationData jenkinsConfigurationData = AppContext.getApplicationContext().getBean(JenkinsConfigurationData.class);
|
||||
|
||||
// gitLabRepositoryService = AppContext.getApplicationContext().getBean(GitLabRepositoryService.class);
|
||||
|
||||
//jenkinsService = AppContext.getApplicationContext().getBean(JenkinsService.class);
|
||||
final DeploymentView deploymentView = new DeploymentView(userConnected);
|
||||
final TableLikeArtefactView tableLikeArtefactView = new TableLikeArtefactView(userConnected);
|
||||
MenuBar menuBar = new MenuBar();
|
||||
navigator.addView("", new WelcomeView(userConnected, menuBar));
|
||||
navigator.addView("Deployment", deploymentView);
|
||||
navigator.addView("AssetUpdate", tableLikeArtefactView);
|
||||
|
||||
layout.setMargin(true);
|
||||
setContent(layout);
|
||||
HorizontalLayout userHorizontal = new HorizontalLayout();
|
||||
TextField urlTextField = new TextField("Kie-Wb url");
|
||||
urlTextField.setValue(configKie.getKiewbUrl());
|
||||
urlTextField.setMaxLength(200);
|
||||
userHorizontal.addComponent(urlTextField);
|
||||
layout.addComponent(userHorizontal);
|
||||
userNameTextField = new TextField("User name");
|
||||
userNameTextField.setValue(configKie.getUserName());
|
||||
userConnected.setUserName(configKie.getUserName());
|
||||
userNameTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
|
||||
@Override
|
||||
public void textChange(FieldEvents.TextChangeEvent textChangeEvent) {
|
||||
userConnected.setUserName(textChangeEvent.getText());
|
||||
}
|
||||
|
||||
MenuBar.MenuItem subMenuDeployment = menuBar.addItem("Deployment", null);
|
||||
MenuBar.MenuItem submenuAsset = menuBar.addItem("Asset", null);
|
||||
|
||||
|
||||
subMenuDeployment.addItem("Option 2", null);
|
||||
|
||||
submenuAsset.addItem("Option 4", null);
|
||||
|
||||
subMenuDeployment.addItem("Deploy", (MenuBar.Command) menuItem -> {
|
||||
navigator.navigateTo("Deployment");
|
||||
deploymentView.refreshCombo();
|
||||
});
|
||||
|
||||
userHorizontal.addComponent(userNameTextField);
|
||||
userpasswdTextField = new PasswordField("Password");
|
||||
userpasswdTextField.setValue(configKie.getPassword());
|
||||
userConnected.setUserPassword(configKie.getPassword());
|
||||
userpasswdTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
|
||||
@Override
|
||||
public void textChange(FieldEvents.TextChangeEvent textChangeEvent) {
|
||||
userConnected.setUserPassword(textChangeEvent.getText());
|
||||
}
|
||||
submenuAsset.addItem("Asset Modification", (MenuBar.Command) selectedItem -> {
|
||||
navigator.navigateTo("AssetUpdate");
|
||||
tableLikeArtefactView.refreshList();
|
||||
});
|
||||
userHorizontal.addComponent(userpasswdTextField);
|
||||
TabSheet tabsheetRepo = new TabSheet();
|
||||
layout.addComponent(tabsheetRepo);
|
||||
|
||||
DeploymentView deploymentView = new DeploymentView(userConnected);
|
||||
tabsheetRepo.addTab(deploymentView, "Deploy");
|
||||
|
||||
|
||||
// this.setContent(menuBar);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
package org.chtijbug.drools.console;
|
||||
|
||||
import com.vaadin.event.FieldEvents;
|
||||
import com.vaadin.navigator.View;
|
||||
import com.vaadin.navigator.ViewChangeListener;
|
||||
import com.vaadin.ui.*;
|
||||
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;
|
||||
|
||||
public class WelcomeView extends VerticalLayout implements View {
|
||||
|
||||
private UserConnected userConnected;
|
||||
private TextField userNameTextField;
|
||||
private PasswordField userpasswdTextField;
|
||||
|
||||
public WelcomeView(UserConnected userConnected, MenuBar menuBar) {
|
||||
this.userConnected = userConnected;
|
||||
final VerticalLayout layout = new VerticalLayout();
|
||||
layout.addComponent(menuBar);
|
||||
KieConfigurationData configKie = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
|
||||
// GitLabConfigurationData configGitLab = AppContext.getApplicationContext().getBean(GitLabConfigurationData.class);
|
||||
// JenkinsConfigurationData jenkinsConfigurationData = AppContext.getApplicationContext().getBean(JenkinsConfigurationData.class);
|
||||
|
||||
// gitLabRepositoryService = AppContext.getApplicationContext().getBean(GitLabRepositoryService.class);
|
||||
|
||||
//jenkinsService = AppContext.getApplicationContext().getBean(JenkinsService.class);
|
||||
|
||||
layout.setMargin(true);
|
||||
this.addComponent(layout);
|
||||
HorizontalLayout userHorizontal = new HorizontalLayout();
|
||||
TextField urlTextField = new TextField("Kie-Wb url");
|
||||
urlTextField.setValue(configKie.getKiewbUrl());
|
||||
urlTextField.setMaxLength(200);
|
||||
userHorizontal.addComponent(urlTextField);
|
||||
layout.addComponent(userHorizontal);
|
||||
userNameTextField = new TextField("User name");
|
||||
userNameTextField.setValue(configKie.getUserName());
|
||||
userConnected.setUserName(configKie.getUserName());
|
||||
userNameTextField.addTextChangeListener((FieldEvents.TextChangeListener) textChangeEvent -> userConnected.setUserName(textChangeEvent.getText()));
|
||||
|
||||
userHorizontal.addComponent(userNameTextField);
|
||||
userpasswdTextField = new PasswordField("Password");
|
||||
userpasswdTextField.setValue(configKie.getPassword());
|
||||
userConnected.setUserPassword(configKie.getPassword());
|
||||
userpasswdTextField.addTextChangeListener((FieldEvents.TextChangeListener) textChangeEvent -> userConnected.setUserPassword(textChangeEvent.getText()));
|
||||
userHorizontal.addComponent(userpasswdTextField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.chtijbug.drools.console.AddLog;
|
||||
import org.chtijbug.drools.console.service.model.kie.JobStatus;
|
||||
import org.chtijbug.drools.console.service.model.kie.Space;
|
||||
import org.drools.guvnor.server.jaxrs.jaxb.Asset;
|
||||
import org.guvnor.rest.client.ProjectResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -33,6 +33,26 @@ public class KieRepositoryService {
|
|||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
|
||||
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
|
||||
.execute(completeurl, HttpMethod.GET, requestCallback(null, 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<String> extractedValue = new ResponseEntity<>(extractedResponse, clientHttpResponse.getHeaders(), clientHttpResponse.getStatusCode());
|
||||
return extractedValue;
|
||||
});
|
||||
String reponseMoteur;
|
||||
|
||||
reponseMoteur = response.getBody();
|
||||
return reponseMoteur;
|
||||
}
|
||||
|
||||
public List<ProjectResponse> getListSpaces2(String url, String username, String password) {
|
||||
String completeurl = url + "/chtijbug/detailedSpaces";
|
||||
logger.info("url moteur reco : " + completeurl);
|
||||
|
|
@ -54,22 +74,22 @@ public class KieRepositoryService {
|
|||
return reponseMoteur;
|
||||
}
|
||||
|
||||
public List<Space> getListSpaces(String url, String username, String password) {
|
||||
String completeurl = url + "/spaces";
|
||||
public List<Asset> getListAssets(String url, String username, String password, String spaceName, String projectName) {
|
||||
String completeurl = url + "/chtijbug/" + spaceName + "/" + projectName + "/assets";
|
||||
logger.info("url moteur reco : " + completeurl);
|
||||
ResponseEntity<List<Space>> response = restTemplateKiewb
|
||||
ResponseEntity<List<Asset>> response = restTemplateKiewb
|
||||
.execute(completeurl, HttpMethod.GET, requestCallback(null, username, password), clientHttpResponse -> {
|
||||
List<Space> extractedResponse = null;
|
||||
List<Asset> extractedResponse = null;
|
||||
if (clientHttpResponse.getBody() != null) {
|
||||
Scanner s = new Scanner(clientHttpResponse.getBody()).useDelimiter("\\A");
|
||||
String result = s.hasNext() ? s.next() : "";
|
||||
Space[] values = mapper.readValue(result, Space[].class);
|
||||
Asset[] values = mapper.readValue(result, Asset[].class);
|
||||
extractedResponse = Arrays.asList(values);
|
||||
}
|
||||
ResponseEntity<List<Space>> extractedValue = new ResponseEntity<>(extractedResponse, clientHttpResponse.getHeaders(), clientHttpResponse.getStatusCode());
|
||||
ResponseEntity<List<Asset>> extractedValue = new ResponseEntity<>(extractedResponse, clientHttpResponse.getHeaders(), clientHttpResponse.getStatusCode());
|
||||
return extractedValue;
|
||||
});
|
||||
List<Space> reponseMoteur;
|
||||
List<Asset> reponseMoteur;
|
||||
|
||||
reponseMoteur = response.getBody();
|
||||
return reponseMoteur;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package org.chtijbug.drools.console.view;
|
||||
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.vaadin.navigator.View;
|
||||
import com.vaadin.navigator.ViewChangeListener;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import org.chtijbug.drools.console.AddLog;
|
||||
import org.chtijbug.drools.console.service.KieRepositoryService;
|
||||
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.drools.guvnor.server.jaxrs.jaxb.Asset;
|
||||
import org.drools.workbench.models.guided.template.backend.RuleTemplateModelXMLPersistenceImpl;
|
||||
import org.drools.workbench.models.guided.template.shared.TemplateModel;
|
||||
|
||||
public class AssetEditView extends VerticalLayout implements AddLog, View {
|
||||
|
||||
final private KieRepositoryService kieRepositoryService;
|
||||
final private KieConfigurationData config;
|
||||
private UserConnected userConnected;
|
||||
private Asset assetToUpdate;
|
||||
private XmlMapper mapper = new XmlMapper();
|
||||
private String spaceName;
|
||||
private String projectName;
|
||||
|
||||
public AssetEditView(UserConnected userConnected, String spaceName, String projectName, Asset assetToUpdate) {
|
||||
this.userConnected = userConnected;
|
||||
this.assetToUpdate = assetToUpdate;
|
||||
this.spaceName = spaceName;
|
||||
this.projectName = projectName;
|
||||
this.kieRepositoryService = AppContext.getApplicationContext().getBean(KieRepositoryService.class);
|
||||
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
|
||||
String assetContent = kieRepositoryService.getAssetSource(config.getKiewbUrl(), userConnected.getUserName(), userConnected.getUserPassword(), spaceName, projectName, assetToUpdate.getTitle());
|
||||
TemplateModel model = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(assetContent);
|
||||
System.out.println("coucou");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRow(String textToAdd) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -12,19 +12,16 @@ import com.vaadin.ui.themes.Runo;
|
|||
import org.chtijbug.drools.console.AddLog;
|
||||
import org.chtijbug.drools.console.service.KieRepositoryService;
|
||||
import org.chtijbug.drools.console.service.KieServerRepositoryService;
|
||||
import org.chtijbug.drools.console.service.model.DisplayData;
|
||||
import org.chtijbug.drools.console.service.model.UserConnected;
|
||||
import org.chtijbug.drools.console.service.model.kie.*;
|
||||
import org.chtijbug.drools.console.service.util.AppContext;
|
||||
import org.guvnor.rest.client.ProjectResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeploymentView extends VerticalLayout implements AddLog, View {
|
||||
|
||||
|
||||
final private List<DisplayData> currentSelected = new ArrayList<>();
|
||||
final private Table table = new Table();
|
||||
final private Button buttonDeployProject = new Button("Deploy project");
|
||||
final private KieConfigurationData config;
|
||||
|
|
@ -44,25 +41,24 @@ public class DeploymentView extends VerticalLayout implements AddLog, View {
|
|||
public DeploymentView(UserConnected userConnected) {
|
||||
|
||||
this.kieRepositoryService = AppContext.getApplicationContext().getBean(KieRepositoryService.class);
|
||||
;
|
||||
|
||||
this.kieServerRepositoryService = AppContext.getApplicationContext().getBean(KieServerRepositoryService.class);
|
||||
;
|
||||
|
||||
this.userConnected = userConnected;
|
||||
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
|
||||
Button button = new Button("Refresh");
|
||||
button.addStyleName(Runo.BUTTON_SMALL);
|
||||
|
||||
button.addClickListener((Button.ClickListener) event -> {
|
||||
this.refreshCombo();
|
||||
this.refreshList();
|
||||
});
|
||||
|
||||
this.addComponent(button);
|
||||
|
||||
List<ProjectResponse> projectResponses = kieRepositoryService.getListSpaces2(config.getKiewbUrl(), userConnected.getUserName(), userConnected.getUserPassword());
|
||||
|
||||
spaceContainer =
|
||||
new BeanItemContainer<ProjectResponse>(ProjectResponse.class);
|
||||
spaceContainer.addAll(projectResponses);
|
||||
ComboBox spaceSelection = new ComboBox("Project", spaceContainer);
|
||||
|
||||
spaceSelection.setNullSelectionAllowed(false);
|
||||
|
|
@ -98,8 +94,8 @@ public class DeploymentView extends VerticalLayout implements AddLog, View {
|
|||
|
||||
|
||||
buttonDeployProject.addClickListener((Button.ClickListener) event -> {
|
||||
if (containerIdTextField.getValue() != null
|
||||
&& containerIdTextField.getValue().length() > 0) {
|
||||
// if (containerIdTextField.getValue() != null
|
||||
// && containerIdTextField.getValue().length() > 0) {
|
||||
table.removeAllItems();
|
||||
|
||||
ProjectResponse response = (ProjectResponse) spaceSelection.getValue();
|
||||
|
|
@ -129,7 +125,7 @@ public class DeploymentView extends VerticalLayout implements AddLog, View {
|
|||
newContainer.getReleaseId().setVersion(projectVersionTextField.getValue());
|
||||
KieContainerInfo createdContainer = kieServerRepositoryService.createContainer(config.getKieserverUrl(), config.getKieserverUserName(), config.getKieserverPassword(), projectArtifactIDTextField.getValue(), newContainer, this);
|
||||
containerIdTextField.setValue(createdContainer.getContainerId());
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
});
|
||||
|
|
@ -150,13 +146,22 @@ public class DeploymentView extends VerticalLayout implements AddLog, View {
|
|||
|
||||
}
|
||||
|
||||
public void refreshCombo() {
|
||||
List<ProjectResponse> projectResponses = kieRepositoryService.getListSpaces2(config.getKiewbUrl(), userConnected.getUserName(), userConnected.getUserPassword());
|
||||
spaceContainer.removeAllItems();
|
||||
|
||||
spaceContainer.addAll(projectResponses);
|
||||
|
||||
}
|
||||
|
||||
private void refreshList() {
|
||||
buttonDeployProject.setEnabled(true);
|
||||
KieConfigurationData config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
|
||||
List<KieContainerInfo> listcontainers = kieServerRepositoryService.getContainerList(config.getKieserverUrl(), config.getKieserverUserName(), config.getKieserverPassword());
|
||||
containerIdTextField.setValue("");
|
||||
for (KieContainerInfo kieContainerInfo : listcontainers) {
|
||||
if (kieContainerInfo.getArtifactId().equals(projectArtifactIDTextField.getValue())
|
||||
if (kieContainerInfo.getArtifactId() != null
|
||||
&& kieContainerInfo.getArtifactId().equals(projectArtifactIDTextField.getValue())
|
||||
&& kieContainerInfo.getArtifactId().equals(projectArtifactIDTextField.getValue())
|
||||
&& kieContainerInfo.getArtifactId().equals(projectArtifactIDTextField.getValue())) {
|
||||
containerIdTextField.setValue(kieContainerInfo.getContainerId());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,158 @@
|
|||
package org.chtijbug.drools.console.view;
|
||||
|
||||
import com.vaadin.data.Property;
|
||||
import com.vaadin.data.util.BeanItemContainer;
|
||||
import com.vaadin.event.Action;
|
||||
import com.vaadin.event.ItemClickEvent;
|
||||
import com.vaadin.navigator.View;
|
||||
import com.vaadin.navigator.ViewChangeListener;
|
||||
import com.vaadin.shared.ui.MultiSelectMode;
|
||||
import com.vaadin.ui.*;
|
||||
import com.vaadin.ui.themes.Runo;
|
||||
import org.chtijbug.drools.console.AddLog;
|
||||
import org.chtijbug.drools.console.service.KieRepositoryService;
|
||||
import org.chtijbug.drools.console.service.KieServerRepositoryService;
|
||||
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.drools.guvnor.server.jaxrs.jaxb.Asset;
|
||||
import org.guvnor.rest.client.ProjectResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TableLikeArtefactView extends VerticalLayout implements AddLog, View {
|
||||
|
||||
final private KieConfigurationData config;
|
||||
final private BeanItemContainer<ProjectResponse> spaceContainer =
|
||||
new BeanItemContainer<ProjectResponse>(ProjectResponse.class);
|
||||
;
|
||||
|
||||
|
||||
final private KieRepositoryService kieRepositoryService;
|
||||
|
||||
final private KieServerRepositoryService kieServerRepositoryService;
|
||||
|
||||
final private UserConnected userConnected;
|
||||
|
||||
final private BeanItemContainer<Asset> assetBeanItemContainer = new BeanItemContainer<>(Asset.class);
|
||||
|
||||
private Table assetTable;
|
||||
|
||||
public TableLikeArtefactView(UserConnected userConnected) {
|
||||
|
||||
this.kieRepositoryService = AppContext.getApplicationContext().getBean(KieRepositoryService.class);
|
||||
|
||||
this.kieServerRepositoryService = AppContext.getApplicationContext().getBean(KieServerRepositoryService.class);
|
||||
|
||||
this.userConnected = userConnected;
|
||||
|
||||
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
|
||||
Button button = new Button("Refresh");
|
||||
button.addStyleName(Runo.BUTTON_SMALL);
|
||||
|
||||
button.addClickListener((Button.ClickListener) event -> {
|
||||
this.refreshList();
|
||||
});
|
||||
|
||||
this.addComponent(button);
|
||||
|
||||
|
||||
ComboBox spaceSelection = new ComboBox("Project", spaceContainer);
|
||||
|
||||
spaceSelection.setNullSelectionAllowed(false);
|
||||
|
||||
spaceSelection.setItemCaptionPropertyId("name");
|
||||
|
||||
spaceSelection.setNewItemsAllowed(false);
|
||||
spaceSelection.setImmediate(true);
|
||||
spaceSelection.addListener(new Property.ValueChangeListener() {
|
||||
@Override
|
||||
public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
|
||||
ProjectResponse response = (ProjectResponse) spaceSelection.getValue();
|
||||
assetBeanItemContainer.removeAllItems();
|
||||
List<Asset> assets = kieRepositoryService.getListAssets(config.getKiewbUrl(), userConnected.getUserName(), userConnected.getUserPassword(), response.getSpaceName(), response.getName());
|
||||
for (Asset asset : assets) {
|
||||
if (asset.getTitle().endsWith(".template")
|
||||
|| asset.getTitle().endsWith(".gdst")) {
|
||||
assetBeanItemContainer.addBean(asset);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
this.addComponent(spaceSelection);
|
||||
assetBeanItemContainer.removeContainerProperty("author");
|
||||
assetBeanItemContainer.removeContainerProperty("binaryLink");
|
||||
assetBeanItemContainer.removeContainerProperty("sourceLink");
|
||||
assetBeanItemContainer.removeContainerProperty("refLink");
|
||||
//assetBeanItemContainer.removeContainerProperty("directory");
|
||||
assetBeanItemContainer.removeContainerProperty("comment");
|
||||
assetBeanItemContainer.removeContainerProperty("content");
|
||||
assetBeanItemContainer.removeContainerProperty("description");
|
||||
assetBeanItemContainer.removeContainerProperty("binaryContentAttachmentFileName");
|
||||
assetBeanItemContainer.removeContainerProperty("published");
|
||||
assetBeanItemContainer.removeContainerProperty("metadata");
|
||||
|
||||
|
||||
assetTable = new Table("List of assets", assetBeanItemContainer);
|
||||
assetTable.setSelectable(true);
|
||||
assetTable.setSizeFull();
|
||||
assetTable.setMultiSelectMode(MultiSelectMode.SIMPLE);
|
||||
assetTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
|
||||
@Override
|
||||
public void itemClick(ItemClickEvent itemClickEvent) {
|
||||
if (itemClickEvent.isCtrlKey()) {
|
||||
Asset selected = (Asset) itemClickEvent.getItemId();
|
||||
System.out.println(itemClickEvent.getItemId().toString());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
this.addComponent(assetTable);
|
||||
final Action actionDuplicate = new Action("Duplicate");
|
||||
final Action actionEdit = new Action("Edit");
|
||||
final Action actionDelete = new Action("Delete");
|
||||
assetTable.addActionHandler(new Action.Handler() {
|
||||
|
||||
public void handleAction(Action action, Object sender,
|
||||
Object target) {
|
||||
if (action.equals(actionDuplicate)) {
|
||||
Notification.show("Duplicate not yet implemented");
|
||||
} else if (action.equals(actionEdit)) {
|
||||
Notification.show("Edit/modification not yet implemented");
|
||||
Asset selected = (Asset) target;
|
||||
ProjectResponse response = (ProjectResponse) spaceSelection.getValue();
|
||||
AssetEditView assetEditView = new AssetEditView(userConnected, response.getSpaceName(), response.getName(), selected);
|
||||
UI.getCurrent().getNavigator().addView("Asset-" + selected.getTitle(), assetEditView);
|
||||
UI.getCurrent().getNavigator().navigateTo("Asset-" + selected.getTitle());
|
||||
} else if (action.equals(actionDelete)) {
|
||||
Notification.show("Delete not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Action[] getActions(Object target, Object sender) {
|
||||
return new Action[]{actionDuplicate, actionEdit, actionDelete};
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void refreshList() {
|
||||
List<ProjectResponse> projectResponses = kieRepositoryService.getListSpaces2(config.getKiewbUrl(), userConnected.getUserName(), userConnected.getUserPassword());
|
||||
spaceContainer.removeAllItems();
|
||||
spaceContainer.addAll(projectResponses);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRow(String textToAdd) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -142,15 +142,13 @@ public class PackageResource {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Path("{organizationalUnitName}/{repositoryName}/{packageName}/assets")
|
||||
@Path("{organizationalUnitName}/{projectName}/assets")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
public Collection<Asset> getAssetsAsJAXB(
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("repositoryName") String repositoryName,
|
||||
@PathParam("packageName") String packageName,
|
||||
@QueryParam("format") List<String> formats) {
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("projectName") String projectName) {
|
||||
try {
|
||||
List<Asset> contentList = new LinkedList<>();
|
||||
WorkspaceProject project = getProject(organizationalUnitName, repositoryName, packageName);
|
||||
WorkspaceProject project = getProject(organizationalUnitName, projectName);
|
||||
if (project != null) {
|
||||
org.uberfire.backend.vfs.Path rootPath = project.getRootPath();
|
||||
org.uberfire.java.nio.file.Path nioPath = Paths.get(rootPath.toURI());
|
||||
|
|
@ -165,16 +163,12 @@ public class PackageResource {
|
|||
}
|
||||
}
|
||||
|
||||
private WorkspaceProject getProject(String organizationalUnitName, String repositoryName, String packageName) {
|
||||
private WorkspaceProject getProject(String organizationalUnitName, String projectName) {
|
||||
OrganizationalUnit organizationalUnit = organizationalUnitService.getOrganizationalUnit(organizationalUnitName);
|
||||
//Collection<Repository> repositories = organizationalUnit.getRepositories();
|
||||
// for (Repository repository : repositories) {
|
||||
// if (repository.getAlias().equals(repositoryName)) {
|
||||
// Optional<Branch> branch = repository.getDefaultBranch();
|
||||
Collection<WorkspaceProject> workspaceProjects = projectService.getAllWorkspaceProjects(organizationalUnit);
|
||||
|
||||
for (WorkspaceProject project : workspaceProjects) {
|
||||
if (project.getName().equals(packageName)) {
|
||||
if (project.getName().equals(projectName)) {
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
|
@ -218,6 +212,26 @@ public class PackageResource {
|
|||
}
|
||||
}
|
||||
|
||||
private String getContentSource(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);
|
||||
String result = getContentSource(adirectoryStream, assetName);
|
||||
if (result != null && result.length() > 0) {
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (elementPath.getFileName().toString().startsWith(".") == false) {
|
||||
if (elementPath.getFileName().toString().equals(assetName)) {
|
||||
return ioService.readAllString(elementPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private org.uberfire.java.nio.file.Path getFileElementPath(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)) {
|
||||
|
|
@ -252,15 +266,14 @@ public class PackageResource {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Path("{organizationalUnitName}/{repositoryName}/{packageName}/assets/{assetName}")
|
||||
@Path("{organizationalUnitName}/{projectName}/assets/{assetName}")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
public Collection<Asset> getAssetAsJaxB(
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("repositoryName") String repositoryName,
|
||||
@PathParam("packageName") String packageName, @PathParam("assetName") String assetName) {
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("projectName") String projectName, @PathParam("assetName") String assetName) {
|
||||
List<Asset> resultList = new LinkedList<>();
|
||||
try {
|
||||
WorkspaceProject project = getProject(organizationalUnitName, repositoryName, packageName);
|
||||
if (project != null && project.getName().equals(packageName)) {
|
||||
WorkspaceProject project = getProject(organizationalUnitName, projectName);
|
||||
if (project != null) {
|
||||
List<Asset> contentList = new LinkedList<>();
|
||||
org.uberfire.backend.vfs.Path rootPath = project.getRootPath();
|
||||
org.uberfire.java.nio.file.Path nioPath = Paths.get(rootPath.toURI());
|
||||
|
|
@ -280,58 +293,44 @@ public class PackageResource {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Path("{organizationalUnitName}/{repositoryName}/{packageName}/assets/{assetName}/source")
|
||||
@Path("{organizationalUnitName}/{projectName}/assets/{assetName}/source")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
public String getAssetSource(
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("repositoryName") String repositoryName,
|
||||
@PathParam("packageName") String packageName, @PathParam("assetName") String assetName) {
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("projectName") String projectName, @PathParam("assetName") String assetName) {
|
||||
List<Asset> resultList = new LinkedList<>();
|
||||
String result = "";
|
||||
try {
|
||||
WorkspaceProject project = getProject(organizationalUnitName, repositoryName, packageName);
|
||||
if (project != null && project.getName().equals(packageName)) {
|
||||
List<Asset> contentList = new LinkedList<>();
|
||||
List<org.uberfire.java.nio.file.Path> pathLinkedList = new LinkedList<>();
|
||||
WorkspaceProject project = getProject(organizationalUnitName, projectName);
|
||||
if (project != null) {
|
||||
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);
|
||||
getContent(directoryStream, contentList);
|
||||
for (Asset asset : contentList) {
|
||||
if (asset.getTitle().equals(assetName)) {
|
||||
resultList.add(asset);
|
||||
DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream2 = ioService.newDirectoryStream(nioPath);
|
||||
getContentSource(directoryStream2, asset, pathLinkedList);
|
||||
if (pathLinkedList.size() == 1) {
|
||||
result = ioService.readAllString(pathLinkedList.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
result = getContentSource(directoryStream, assetName);
|
||||
}
|
||||
return result;
|
||||
} catch (RuntimeException e) {
|
||||
throw new WebApplicationException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{organizationalUnitName}/{repositoryName}/{packageName}/asset/{assetName}")
|
||||
@Path("{organizationalUnitName}/{projectName}/asset/{assetName}")
|
||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
public void updateAssetFromJAXB(
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("repositoryName") String repositoryName,
|
||||
@PathParam("packageName") String packageName,
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("projectName") String projectName,
|
||||
@PathParam("assetName") String assetName, String asset) {
|
||||
updateAssetContent(organizationalUnitName, repositoryName, packageName, assetName, asset);
|
||||
updateAssetContent(organizationalUnitName, projectName, assetName, asset);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{organizationalUnitName}/{repositoryName}/{packageName}/newAsset")
|
||||
@Path("{organizationalUnitName}/{projectName}/newAsset")
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
public Asset createAssetFromSourceAndJAXB(
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("repositoryName") String repositoryName,
|
||||
@PathParam("packageName") String packageName, Asset asset) {
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("projectName") String projectName, Asset asset) {
|
||||
try {
|
||||
WorkspaceProject project = getProject(organizationalUnitName, repositoryName, packageName);
|
||||
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);
|
||||
|
|
@ -350,21 +349,20 @@ public class PackageResource {
|
|||
}
|
||||
|
||||
@PUT
|
||||
@Path("{organizationalUnitName}/{repositoryName}/{packageName}/asset/{assetName}/source")
|
||||
@Path("{organizationalUnitName}/{projectName}/asset/{assetName}/source")
|
||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
|
||||
@Produces({MediaType.WILDCARD})
|
||||
public void updateAssetSource(
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("repositoryName") String repositoryName,
|
||||
@PathParam("packageName") String packageName, @PathParam("assetName") String assetName, String content) {
|
||||
updateAssetContent(organizationalUnitName, repositoryName, packageName, assetName, content);
|
||||
@PathParam("organizationalUnitName") String organizationalUnitName, @PathParam("projectName") String projectName, @PathParam("assetName") String assetName, String content) {
|
||||
updateAssetContent(organizationalUnitName, projectName, assetName, content);
|
||||
|
||||
}
|
||||
|
||||
private void updateAssetContent(String organizationalUnitName, String repositoryName, String packageName, String assetName, String content) {
|
||||
private void updateAssetContent(String organizationalUnitName, String projectName, String assetName, String content) {
|
||||
try {
|
||||
WorkspaceProject project = getProject(organizationalUnitName, repositoryName, packageName);
|
||||
WorkspaceProject project = getProject(organizationalUnitName, projectName);
|
||||
|
||||
if (project != null && project.getName().equals(packageName)) {
|
||||
if (project != null) {
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue