Jira-integration: start point of synchronization with jira
Here starts the process synchronization of order-elements with jira issues First it request jira for all labels and renders the response as autocompleted list (in edition UI). When a user selected a label and press 'startsync' button it requests jira for all issues of the selected label and starts synchronizing order-elements(syncOrderElementsWithJiraIssues(order,issues). After finishing synchronization it saves the order bij calling saveAndContinue() method. if save order is ok then starts synchronizing timesheets. Finally diplays a dialog window with success or failer info.
This commit is contained in:
parent
553b19e5e0
commit
544cfeedb5
1 changed files with 157 additions and 0 deletions
|
|
@ -27,6 +27,7 @@ import java.util.ConcurrentModificationException;
|
|||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
|
@ -37,6 +38,7 @@ import javax.annotation.Resource;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.externalcompanies.entities.DeadlineCommunication;
|
||||
import org.libreplan.business.externalcompanies.entities.DeliverDateComparator;
|
||||
|
|
@ -50,6 +52,10 @@ import org.libreplan.business.orders.entities.OrderStatusEnum;
|
|||
import org.libreplan.business.planner.entities.PositionConstraintType;
|
||||
import org.libreplan.business.templates.entities.OrderTemplate;
|
||||
import org.libreplan.business.users.entities.UserRole;
|
||||
import org.libreplan.importers.IJiraOrderElementSynchronizer;
|
||||
import org.libreplan.importers.IJiraTimesheetSynchronizer;
|
||||
import org.libreplan.importers.JiraSyncInfo;
|
||||
import org.libreplan.importers.jira.Issue;
|
||||
import org.libreplan.web.common.ConfirmCloseUtil;
|
||||
import org.libreplan.web.common.IMessagesForUser;
|
||||
import org.libreplan.web.common.Level;
|
||||
|
|
@ -77,6 +83,7 @@ import org.zkoss.ganttz.util.LongOperationFeedback;
|
|||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.Desktop;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.SuspendNotAllowedException;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
|
|
@ -94,7 +101,9 @@ import org.zkoss.zul.Datebox;
|
|||
import org.zkoss.zul.Grid;
|
||||
import org.zkoss.zul.Hbox;
|
||||
import org.zkoss.zul.Label;
|
||||
import org.zkoss.zul.ListModel;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Popup;
|
||||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.RowRenderer;
|
||||
import org.zkoss.zul.Rows;
|
||||
|
|
@ -191,6 +200,16 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
|
||||
private EndDatesRenderer endDatesRenderer = new EndDatesRenderer();
|
||||
|
||||
@Autowired
|
||||
private IJiraOrderElementSynchronizer jiraOrderElementSynchronizer;
|
||||
|
||||
@Autowired
|
||||
private IJiraTimesheetSynchronizer jiraTimesheetSynchronizer;
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
|
|
@ -1679,4 +1698,142 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
return Util.getCurrencySymbol();
|
||||
}
|
||||
|
||||
private Popup jirasyncPopup;
|
||||
private Button startJiraSyncButton, cancelJiraSyncButton, syncWithJiraButton;
|
||||
private Combobox comboJiraLabel;
|
||||
|
||||
public boolean isJiraDeactivated() {
|
||||
return !configurationDAO.getConfigurationWithReadOnlyTransaction()
|
||||
.getJiraConfiguration().isJiraActivated();
|
||||
}
|
||||
|
||||
public void syncWithJira(Event event) {
|
||||
|
||||
List<String> items = jiraOrderElementSynchronizer.getAllJiraLabels();
|
||||
|
||||
Textbox txtImportedLabel = (Textbox) editWindow
|
||||
.getFellowIfAny("txtImportedLabel");
|
||||
|
||||
if (!(txtImportedLabel.getText()).isEmpty()) {
|
||||
startSyncWithJira(txtImportedLabel.getText());
|
||||
return;
|
||||
}
|
||||
|
||||
setupJiraSyncPopup(editWindow, new SimpleListModelExt(items));
|
||||
|
||||
syncWithJiraButton = (Button) getCurrentTab().getFellow(
|
||||
"syncWithJiraButton");
|
||||
|
||||
jirasyncPopup.open(syncWithJiraButton, "before_start");
|
||||
}
|
||||
|
||||
|
||||
public void startSyncWithJira(String label) {
|
||||
Order order = getOrder();
|
||||
|
||||
List<Issue> issues = jiraOrderElementSynchronizer.getJiraIssues(label);
|
||||
|
||||
order.setCodeAutogenerated(false);
|
||||
order.setImportedLabel(label);
|
||||
|
||||
jiraOrderElementSynchronizer.syncOrderElementsWithJiraIssues(order,
|
||||
issues);
|
||||
|
||||
saveAndContinue(false);
|
||||
if (jirasyncPopup != null) {
|
||||
jirasyncPopup.close();
|
||||
}
|
||||
|
||||
jiraTimesheetSynchronizer
|
||||
.syncJiraTimesheetWithJiraIssues(issues, order);
|
||||
|
||||
showSyncInfo();
|
||||
}
|
||||
|
||||
private void showSyncInfo() {
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
|
||||
JiraSyncInfo jiraSyncInfoProgress = jiraOrderElementSynchronizer
|
||||
.getJiraSyncInfo();
|
||||
args.put("showSyncProgressSuccess",
|
||||
jiraSyncInfoProgress.isSyncSuccessful());
|
||||
args.put("jiraSyncProgressFailedReasons", new SimpleListModel(
|
||||
jiraSyncInfoProgress.getSyncFailedReasons()));
|
||||
|
||||
JiraSyncInfo jiraSyncInfoTimesheet = jiraTimesheetSynchronizer
|
||||
.getJiraSyncInfo();
|
||||
args.put("showSyncTimesheetSuccess",
|
||||
jiraSyncInfoTimesheet.isSyncSuccessful());
|
||||
args.put("jiraSyncTimesheetFailedReasons", new SimpleListModel(
|
||||
jiraSyncInfoTimesheet.getSyncFailedReasons()));
|
||||
|
||||
Window jiraSyncInfoWindow = (Window) Executions.createComponents(
|
||||
"/orders/_jiraSyncInfo.zul", null, args);
|
||||
|
||||
try {
|
||||
jiraSyncInfoWindow.doModal();
|
||||
} catch (SuspendNotAllowedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupJiraSyncPopup(Component comp, ListModel model) {
|
||||
|
||||
startJiraSyncButton = (Button) comp.getFellow("startJiraSyncButton");
|
||||
startJiraSyncButton.setLabel(_("Start sync"));
|
||||
|
||||
startJiraSyncButton.addEventListener(Events.ON_CLICK, new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
startSyncWithJira(comboJiraLabel.getValue());
|
||||
}
|
||||
});
|
||||
cancelJiraSyncButton = (Button) comp.getFellow("cancelJiraSyncButton");
|
||||
cancelJiraSyncButton.setLabel(_("Cancel"));
|
||||
cancelJiraSyncButton.addEventListener(Events.ON_CLICK, new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
jirasyncPopup.close();
|
||||
}
|
||||
});
|
||||
comboJiraLabel = (Combobox) comp.getFellowIfAny("comboJiraLabel");
|
||||
comboJiraLabel.setModel(model);
|
||||
|
||||
jirasyncPopup = (Popup) comp.getFellow("jirasyncPopup");
|
||||
|
||||
}
|
||||
|
||||
private class SimpleListModelExt extends SimpleListModel {
|
||||
|
||||
public SimpleListModelExt(List data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public ListModel getSubModel(Object value, int nRows) {
|
||||
final String idx = value == null ? "" : objectToString(value);
|
||||
if (nRows < 0) {
|
||||
nRows = 10;
|
||||
}
|
||||
final LinkedList data = new LinkedList();
|
||||
for (int i = 0; i < getSize(); i++) {
|
||||
if (idx.equals("")
|
||||
|| entryMatchesText(getElementAt(i).toString(), idx)) {
|
||||
data.add(getElementAt(i));
|
||||
if (--nRows <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SimpleListModelExt(data);
|
||||
}
|
||||
|
||||
public boolean entryMatchesText(String entry, String text) {
|
||||
return entry.toLowerCase().startsWith(text.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue