Skip to content

Commit

Permalink
Merge pull request #2 from nqhoan-axonivy/dev
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
nqhoan-axonivy authored Jan 5, 2024
2 parents 0a480b5 + 0b8c3e2 commit a9ef3f5
Show file tree
Hide file tree
Showing 48 changed files with 20,646 additions and 603 deletions.
24 changes: 19 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
work/config-cache-app-designer.properties
.metadata/.lock
.metadata/.log
.metadata/version.ini
.metadata/.plugins/*
# general
Thumbs.db
.DS_Store
*~
*.log

# java
*.class
hs_err_pid*

# maven
target/
lib/mvn-deps/

# ivy
classes/
src_dataClasses/
src_wsproc/
logs/
1 change: 1 addition & 0 deletions salesforce-connector-demo/cms/cms_en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Dialogs:
action: Action
amount: Amount
closeDate: Close Date
listOpps: List Opportunities
oppName: Opportunity Name
stage: Stage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
findAllEventByOpportunityIdData #class
FindAllEventByOpportunityIdData #class
salesforce.connector.demo #namespace
events java.util.List<com.axonivy.connector.salesforce.model.Event> #field
oppId String #field
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
findAllTaskByOpportunityIdData #class
FindAllTaskByOpportunityIdData #class
salesforce.connector.demo #namespace
tasks java.util.List<com.axonivy.connector.salesforce.model.Task> #field
oppId String #field
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
getOppotunityData #class
GetOppotunityData #class
salesforce.connector.demo #namespace
opp com.axonivy.connector.salesforce.model.Opportunity #field
id String #field
4 changes: 2 additions & 2 deletions salesforce-connector-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.axonivy.salesforce.connector.demo</groupId>
<groupId>com.axonivy.connector.salesforce</groupId>
<artifactId>salesforce-connector-demo</artifactId>
<version>1.0.0</version>
<version>10.0.12-SNAPSHOT</version>
<packaging>iar</packaging>
<dependencies>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions salesforce-connector-demo/processes/ChartDemo.p.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
}, {
"id" : "f2",
"type" : "UserTask",
"name" : "Chart Demo",
"name" : "ChartDemo",
"config" : {
"dialogId" : "salesforce.connector.demo.Chart",
"startMethod" : "start()",
"case" : {
"name" : "Chart Demo",
"name" : "ChartDemo",
"description" : "Chart Demo"
},
"task" : {
"name" : "Chart Demo",
"name" : "ChartDemo",
"description" : "Chart Demo",
"skipTasklist" : true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id" : "18C19E836CE959F3",
"kind" : "CALLABLE_SUB",
"config" : {
"data" : "salesforce.connector.demo.findAllEventByOpportunityIdData"
"data" : "salesforce.connector.demo.FindAllEventByOpportunityIdData"
},
"elements" : [ {
"id" : "f0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id" : "18C19E6F2ADC725A",
"kind" : "CALLABLE_SUB",
"config" : {
"data" : "salesforce.connector.demo.findAllTaskByOpportunityIdData"
"data" : "salesforce.connector.demo.FindAllTaskByOpportunityIdData"
},
"elements" : [ {
"id" : "f0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id" : "18BB87D903C86664",
"kind" : "CALLABLE_SUB",
"config" : {
"data" : "salesforce.connector.demo.getOppotunityData"
"data" : "salesforce.connector.demo.GetOppotunityData"
},
"elements" : [ {
"id" : "f0",
Expand Down Expand Up @@ -47,7 +47,7 @@
"output" : {
"map" : {
"out" : "in",
"out.opp" : "result.oppotunity"
"out.opp" : "result.opportunity"
}
},
"call" : {
Expand Down
4 changes: 2 additions & 2 deletions salesforce-connector-demo/processes/ListDemo.p.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"startMethod" : "start()",
"case" : {
"name" : "Opportunities",
"description" : "Opportunities"
"description" : "List Opportunities"
},
"task" : {
"name" : "Opportunities",
"description" : "Opportunities",
"description" : "List Opportunities",
"skipTasklist" : true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class ChartBean {
public ChartBean() {
opps = new ArrayList<>();
opportunities = Utils.getAllOpps();
Ivy.log().info("list opportunities: " + opportunities.size());

opps = Utils.convertToOppDTO(opportunities);

Expand Down Expand Up @@ -87,13 +86,11 @@ public void createBarChartModel() {

barModel.setData(data);

//Options
//Options
BarChartOptions options = new BarChartOptions();
// options.setMaintainAspectRatio(false);
CartesianScales cScales = new CartesianScales();
CartesianLinearAxes linearAxes = new CartesianLinearAxes();
linearAxes.setOffset(true);
// linearAxes.setBeginAtZero(true);
CartesianLinearTicks ticks = new CartesianLinearTicks();
linearAxes.setTicks(ticks);
cScales.addYAxesData(linearAxes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.primefaces.model.charts.ChartData;
import org.primefaces.model.charts.axes.cartesian.CartesianScales;
import org.primefaces.model.charts.axes.cartesian.linear.CartesianLinearAxes;
import org.primefaces.model.charts.axes.cartesian.linear.CartesianLinearTicks;
import org.primefaces.model.charts.bar.BarChartDataSet;
import org.primefaces.model.charts.bar.BarChartModel;
import org.primefaces.model.charts.bar.BarChartOptions;
import org.primefaces.model.charts.optionconfig.animation.Animation;
import org.primefaces.model.charts.optionconfig.legend.Legend;
import org.primefaces.model.charts.optionconfig.legend.LegendLabel;
import org.primefaces.model.charts.optionconfig.title.Title;
import org.primefaces.util.LangUtils;

import com.axonivy.connector.salesforce.model.Account;
Expand All @@ -45,139 +35,124 @@ public class ListOppsBean {
private List<String> stages;
private OpportunityUpdateDTO updateDTO;
private ActivityDTO activityDTO;

public ListOppsBean() {
ownerId= "0055h000009a4XMAAY";
ownerId = "0055h000009a4XMAAY";
opps = new ArrayList<>();
getAllOpps();
Ivy.log().info("list opportunities: " + opportunities.size());


opps = Utils.convertToOppDTO(opportunities);

}

public void openOpportunityDetail(String id) {
selectedOpp = SubProcessCall.withPath("Functional Processes/getOpportunity")
.withStartSignature("getOpportunity(String)")
.withParam("id", id)
.call()
.get("opp", Opportunity.class);
.withStartSignature("getOpportunity(String)").withParam("id", id).call().get("opp", Opportunity.class);
accountName = Utils.getAccName(selectedOpp.getAccountId());
getActivities();
}

private void getActivities() {
activityDTO = new ActivityDTO();
activityDTO.setTasks(Utils.getAllTasks(selectedOpp.getId()));
activityDTO.setEvents(Utils.getAllEvents(selectedOpp.getId()));
activityDTO.setEvents(Utils.getAllEvents(selectedOpp.getId()));
}

public void getAllOpps() {
opportunities = Utils.getAllOpps();
}

@SuppressWarnings("unchecked")
public void getAllAccounts() {
accs = (List<Account>) SubProcessCall.withPath("Functional Processes/getAccounts")
.withStartSignature("getAllAccounts()")
.call()
.get("accs", Account.class);
.withStartSignature("getAllAccounts()").call().get("accs", Account.class);
}

public void addNewOppotunity() {
accountName = null;
selectedOpp = new Opportunity();
selectedOpp.setOwnerId(ownerId);
getAllAccounts();
getListStages();
}

public void updateOppotunity(String id) {
updateDTO = new OpportunityUpdateDTO();
openOpportunityDetail(id);
getAllAccounts();
getListStages();
}

public void convertToUpdateDTO() throws IllegalAccessException, InvocationTargetException {
selectedOpp.setAccountId(getAccountIdByName(accountName));
updateDTO = ConvertUtils.convertToOpportunityObjUpdate(selectedOpp);
}

public void updateCurrentListAfterUpdate() {
OptionalInt result = IntStream.range(0, opps.size())
.filter(x -> selectedOpp.getId().equals(opps.get(x).getId()))
.findFirst();
if (result.isPresent())
{
int index = result.getAsInt();
opps.set(index, Utils.convertToOppDTO(selectedOpp, updateDTO));
.filter(x -> selectedOpp.getId().equals(opps.get(x).getId())).findFirst();
if (result.isPresent()) {
int index = result.getAsInt();
opps.set(index, Utils.convertToOppDTO(selectedOpp, updateDTO));
}
}

public void beforeDelete(String id) {
selectedOpp = SubProcessCall.withPath("Functional Processes/getOpportunity")
.withStartSignature("getOpportunity(String)")
.withParam("id", id)
.call()
.get("opp", Opportunity.class);
.withStartSignature("getOpportunity(String)").withParam("id", id).call().get("opp", Opportunity.class);
}

public void updateCurrentListAfterDelete() {
OptionalInt result = IntStream.range(0, opps.size())
.filter(x -> selectedOpp.getId().equals(opps.get(x).getId()))
.findFirst();
if (result.isPresent())
{
int index = result.getAsInt();
opps.remove(index);
.filter(x -> selectedOpp.getId().equals(opps.get(x).getId())).findFirst();
if (result.isPresent()) {
int index = result.getAsInt();
opps.remove(index);
}
}

private void getListStages() {
stages = Arrays.stream(Stage
.values())
.map(e -> e.getLabel())
.collect(Collectors.toList());
stages = Arrays.stream(Stage.values()).map(e -> e.getLabel()).collect(Collectors.toList());
}

public List<String> completeAccount(String query) {
String queryLowerCase = query.toLowerCase();
List<String> accountList = new ArrayList<>();
List<Account> acccountList = accs;
for (Account acc : acccountList) {
accountList.add(acc.getName());
}

return accountList.stream().filter(t -> t.toLowerCase().startsWith(queryLowerCase)).collect(Collectors.toList());
}

String queryLowerCase = query.toLowerCase();
List<String> accountList = new ArrayList<>();
List<Account> acccountList = accs;
for (Account acc : acccountList) {
accountList.add(acc.getName());
}

return accountList.stream().filter(t -> t.toLowerCase().startsWith(queryLowerCase))
.collect(Collectors.toList());
}

public String getAccountIdByName(String name) {
String accId = null;
Account acc = accs.stream().filter(t -> t.getName().equals(name)).findFirst().orElse(null);
if(acc != null) accId = acc.getId();
Account acc = accs.stream().filter(t -> t.getName().equals(name)).findFirst().orElse(null);
if (acc != null)
accId = acc.getId();
return accId;
}

public void reset() {
selectedOpp = new Opportunity();
accountName = null;
}

public boolean globalFilterFunction(Object value, Object filter, Locale locale) {
String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase();
if (LangUtils.isBlank(filterText)) {
return true;
}

OpportunityDTO opp = (OpportunityDTO) value;
return opp.getOppName().toLowerCase().contains(filterText)
|| opp.getAccName().toLowerCase().contains(filterText)
|| opp.getStage().toLowerCase().contains(filterText)
|| opp.getCloseDate().toString().toLowerCase().contains(filterText)
;
}

String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase();
if (LangUtils.isBlank(filterText)) {
return true;
}

OpportunityDTO opp = (OpportunityDTO) value;
return opp.getOppName().toLowerCase().contains(filterText)
|| opp.getAccName().toLowerCase().contains(filterText)
|| opp.getStage().toLowerCase().contains(filterText)
|| opp.getCloseDate().toString().toLowerCase().contains(filterText);
}

public String getAccountName(String id) {
return Utils.getAccName(id);
}
Expand Down Expand Up @@ -265,5 +240,5 @@ public ActivityDTO getActivityDTO() {
public void setActivityDTO(ActivityDTO activityDTO) {
this.activityDTO = activityDTO;
}

}
Loading

0 comments on commit a9ef3f5

Please sign in to comment.