mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-30 01:16:40 +00:00
code refactoring
This commit is contained in:
+1
-1
@@ -181,7 +181,7 @@ public class AdminConsoleEntryPoint extends AbstractEntryPoint implements Regatt
|
||||
ResultImportUrlsManagementPanel resultImportUrlsManagementPanel = new ResultImportUrlsManagementPanel(sailingService, this, stringMessages);
|
||||
addToTabPanel(tabPanel, user, resultImportUrlsManagementPanel, stringMessages.resultImportUrls(), AdminConsoleFeatures.MANAGE_RESULT_IMPORT_URLS);
|
||||
|
||||
StructureImportUrlsManagementPanel structureImportUrlsManagementPanel = new StructureImportUrlsManagementPanel(sailingService, this, stringMessages, this, eventManagementPanel);
|
||||
StructureImportManagementPanel structureImportUrlsManagementPanel = new StructureImportManagementPanel(sailingService, this, stringMessages, this, eventManagementPanel);
|
||||
addToTabPanel(tabPanel, user, structureImportUrlsManagementPanel, stringMessages.structureImportUrls(), AdminConsoleFeatures.MANAGE_STRUCTURE_IMPORT_URLS);
|
||||
|
||||
RemoteSailingServerInstancesManagementPanel sailingServerInstancesManagementPanel = new RemoteSailingServerInstancesManagementPanel(sailingService, this, stringMessages);
|
||||
|
||||
-35
@@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.ui.CheckBox;
|
||||
import com.google.gwt.user.client.ui.Grid;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
@@ -22,7 +21,6 @@ import com.sap.sse.gwt.client.dialog.DataEntryDialog;
|
||||
|
||||
|
||||
public class RegattaImportDialog extends DataEntryDialog<String>{
|
||||
private final AdminConsoleResources resources = GWT.create(AdminConsoleResources.class);
|
||||
protected StringMessages stringMessages;
|
||||
protected TextBox nameEntryField;
|
||||
protected TextArea descriptionEntryField;
|
||||
@@ -45,38 +43,8 @@ public class RegattaImportDialog extends DataEntryDialog<String>{
|
||||
com.sap.sse.gwt.client.dialog.DataEntryDialog.DialogCallback<String> callback) {
|
||||
super("Regattas"/*title*/, null/*message*/, stringMessages.ok(), stringMessages.cancel(), validator, false/*animationEnables; raus?*/, callback);
|
||||
this.stringMessages = stringMessages;
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
// this.stringMessages = stringMessages;
|
||||
// final ValueChangeHandler<List<String>> valueChangeHandler = new ValueChangeHandler<List<String>>() {
|
||||
// @Override
|
||||
// public void onValueChange(ValueChangeEvent<List<String>> event) {
|
||||
// validate();
|
||||
// }
|
||||
// };
|
||||
// courseAreaNameList = new StringListInlineEditorComposite(Collections.<String> emptyList(),
|
||||
// new StringListInlineEditorComposite.ExpandedUi(stringMessages, resources.removeIcon(), /* suggestValues */
|
||||
// SuggestedCourseAreaNames.suggestedCourseAreaNames));
|
||||
// courseAreaNameList.addValueChangeHandler(valueChangeHandler);
|
||||
// final List<String> imageSuggestionURLs = Arrays.asList(new String[] { "http://", "https://", "http://www.", "https://www" });
|
||||
// imageURLList = new StringListInlineEditorComposite(Collections.<String> emptyList(),
|
||||
// new StringListInlineEditorComposite.ExpandedUi(stringMessages, resources.removeIcon(),
|
||||
// /* suggestValues */ imageSuggestionURLs));
|
||||
// imageURLList.addValueChangeHandler(valueChangeHandler);
|
||||
// List<String> videoURLSuggestions = new ArrayList<>(imageSuggestionURLs);
|
||||
// videoURLSuggestions.add("http://www.youtube.com/watch?v=");
|
||||
// videoURLList = new StringListInlineEditorComposite(Collections.<String> emptyList(),
|
||||
// new StringListInlineEditorComposite.ExpandedUi(stringMessages, resources.removeIcon(),
|
||||
// /* suggestValues */ videoURLSuggestions));
|
||||
// videoURLList.addValueChangeHandler(valueChangeHandler);
|
||||
// sponsorImageURLList = new StringListInlineEditorComposite(Collections.<String> emptyList(),
|
||||
// new StringListInlineEditorComposite.ExpandedUi(stringMessages, resources.removeIcon(),
|
||||
// /* suggestValues */ imageSuggestionURLs));
|
||||
// sponsorImageURLList.addValueChangeHandler(valueChangeHandler);
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected Widget getAdditionalWidget() {
|
||||
final VerticalPanel panel = new VerticalPanel();
|
||||
@@ -118,9 +86,6 @@ public class RegattaImportDialog extends DataEntryDialog<String>{
|
||||
|
||||
protected String getResult() {
|
||||
EventDTO result = new EventDTO();
|
||||
// for (LeaderboardGroupDTO lg : leaderboardGroups) {
|
||||
// result.addLeaderboardGroup(lg);
|
||||
// }
|
||||
result.setName(nameEntryField.getText());
|
||||
result.setDescription(descriptionEntryField.getText());
|
||||
result.setOfficialWebsiteURL(officialWebsiteURLEntryField.getText().trim().isEmpty() ? null : officialWebsiteURLEntryField.getText().trim());
|
||||
|
||||
+3
-9
@@ -42,10 +42,7 @@ public class StructureImportListComposite extends Composite implements RegattasD
|
||||
|
||||
private final Label noRegattasLabel;
|
||||
|
||||
private final SailingServiceAsync sailingService;
|
||||
private final RegattaSelectionProvider regattaSelectionProvider;
|
||||
private final ErrorReporter errorReporter;
|
||||
private final RegattaRefresher regattaRefresher;
|
||||
private final StringMessages stringMessages;
|
||||
|
||||
private final LabeledAbstractFilterablePanel<RegattaDTO> filterablePanelRegattas;
|
||||
@@ -62,10 +59,7 @@ public class StructureImportListComposite extends Composite implements RegattasD
|
||||
public StructureImportListComposite(final SailingServiceAsync sailingService,
|
||||
final RegattaSelectionProvider regattaSelectionProvider, RegattaRefresher regattaRefresher,
|
||||
final ErrorReporter errorReporter, final StringMessages stringMessages, String s) {
|
||||
this.sailingService = sailingService; /* Zuweisung vllt raus? */
|
||||
this.regattaSelectionProvider = regattaSelectionProvider;
|
||||
this.regattaRefresher = regattaRefresher;
|
||||
this.errorReporter = errorReporter;
|
||||
this.stringMessages = stringMessages;
|
||||
AdminConsoleTableResources tableResources = GWT.create(AdminConsoleTableResources.class);
|
||||
this.selectionCheckboxColumn = new SelectionCheckboxColumn<RegattaDTO>(tableResources.cellTableStyle()
|
||||
@@ -92,7 +86,7 @@ public class StructureImportListComposite extends Composite implements RegattasD
|
||||
panel.add(noRegattasLabel);
|
||||
|
||||
regattaListDataProvider = new ListDataProvider<RegattaDTO>();
|
||||
regattaTable = createRegattaImportTable();
|
||||
regattaTable = createRegattaTable();
|
||||
regattaTable.ensureDebugId("RegattasCellTable");
|
||||
regattaTable.setVisible(false);
|
||||
filterablePanelRegattas = new LabeledAbstractFilterablePanel<RegattaDTO>(filterRegattasLabel, allRegattas,
|
||||
@@ -161,9 +155,9 @@ public class StructureImportListComposite extends Composite implements RegattasD
|
||||
return allRegattas;
|
||||
}
|
||||
|
||||
// create Regatta Table in StructureImportURLManagementPanel
|
||||
// create Regatta Table in StructureImportManagementPanel
|
||||
|
||||
private CellTable<RegattaDTO> createRegattaImportTable() {
|
||||
private CellTable<RegattaDTO> createRegattaTable() {
|
||||
CellTable<RegattaDTO> table = new CellTable<RegattaDTO>(/* pageSize */10000, tableRes);
|
||||
regattaListDataProvider.addDataDisplay(table);
|
||||
table.setWidth("100%");
|
||||
|
||||
+73
-146
@@ -3,18 +3,13 @@ package com.sap.sailing.gwt.ui.adminconsole;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.base.ProgressBarBase.Style;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ChangeEvent;
|
||||
import com.google.gwt.event.dom.client.ChangeHandler;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
@@ -22,7 +17,6 @@ import com.google.gwt.user.client.ui.Grid;
|
||||
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.ListBox;
|
||||
import com.google.gwt.user.client.ui.Panel;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.sap.sailing.domain.common.RegattaIdentifier;
|
||||
@@ -30,7 +24,6 @@ import com.sap.sailing.gwt.ui.client.ErrorReporter;
|
||||
import com.sap.sailing.gwt.ui.client.RegattaRefresher;
|
||||
import com.sap.sailing.gwt.ui.client.RegattaSelectionModel;
|
||||
import com.sap.sailing.gwt.ui.client.RegattaSelectionProvider;
|
||||
import com.sap.sailing.gwt.ui.client.RegattasDisplayer;
|
||||
import com.sap.sailing.gwt.ui.client.SailingServiceAsync;
|
||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
import com.sap.sailing.gwt.ui.client.TextfieldEntryDialog;
|
||||
@@ -40,9 +33,7 @@ import com.sap.sailing.gwt.ui.shared.RegattaDTO;
|
||||
import com.sap.sse.gwt.client.dialog.DataEntryDialog;
|
||||
import com.sap.sse.gwt.client.dialog.DataEntryDialog.DialogCallback;
|
||||
|
||||
public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
private final ListBox urlProviderSelectionListBox;
|
||||
private final ListBox urlListBox;
|
||||
public class StructureImportManagementPanel extends FlowPanel {
|
||||
|
||||
private final SailingServiceAsync sailingService;
|
||||
private final ErrorReporter errorReporter;
|
||||
@@ -53,54 +44,37 @@ public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
private RegattaSelectionProvider regattaSelectionProvider;
|
||||
private Panel progressPanel;
|
||||
|
||||
private final Button addButton;
|
||||
private final Button removeButton;
|
||||
private final Button refreshButton;
|
||||
private final Button importDetailsButton;
|
||||
private Button addButton;
|
||||
private Button removeButton;
|
||||
private Button importDetailsButton;
|
||||
|
||||
private StructureImportProgressBar progressBar;
|
||||
private Label overallName;
|
||||
private int parsed;
|
||||
|
||||
public StructureImportUrlsManagementPanel(SailingServiceAsync sailingService, ErrorReporter errorReporter,
|
||||
public StructureImportManagementPanel(SailingServiceAsync sailingService, ErrorReporter errorReporter,
|
||||
StringMessages stringMessages, RegattaRefresher regattaRefresher, EventManagementPanel eventManagementPanel) {
|
||||
this.eventManagementPanel = eventManagementPanel;
|
||||
this.sailingService = sailingService;
|
||||
this.errorReporter = errorReporter;
|
||||
this.stringMessages = stringMessages;
|
||||
this.regattaRefresher = regattaRefresher;
|
||||
progressPanel = new FlowPanel();
|
||||
urlListBox = new ListBox(/* multiple select */true);
|
||||
urlProviderSelectionListBox = new ListBox(false);
|
||||
urlProviderSelectionListBox.addChangeHandler(new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
int selectedIndex = urlProviderSelectionListBox.getSelectedIndex();
|
||||
boolean buttonsEnabled = selectedIndex > 0;
|
||||
addButton.setEnabled(buttonsEnabled);
|
||||
removeButton.setEnabled(buttonsEnabled);
|
||||
refreshButton.setEnabled(buttonsEnabled);
|
||||
refreshUrlList();
|
||||
}
|
||||
});
|
||||
createUI();
|
||||
|
||||
addButton = new Button(stringMessages.add());
|
||||
removeButton = new Button(stringMessages.remove());
|
||||
refreshButton = new Button(stringMessages.refresh());
|
||||
importDetailsButton = new Button(stringMessages.importRegatta());
|
||||
}
|
||||
|
||||
private void createUI() {
|
||||
progressPanel = new FlowPanel();
|
||||
|
||||
addButton = new Button(this.stringMessages.add());
|
||||
removeButton = new Button(this.stringMessages.remove());
|
||||
importDetailsButton = new Button(this.stringMessages.importRegatta());
|
||||
importDetailsButton.setEnabled(false);
|
||||
importDetailsButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
List<RegattaDTO> regattaDTOs = new ArrayList<RegattaDTO>();
|
||||
for (RegattaIdentifier selectedRegatta : regattaSelectionProvider.getSelectedRegattas()) {
|
||||
for (RegattaDTO regattaDTO : regattaListComposite.getAllRegattas()) {
|
||||
if (regattaDTO.getRegattaIdentifier().equals(selectedRegatta)) {
|
||||
regattaDTOs.add(regattaDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
createEventDetails(regattaDTOs);
|
||||
List<RegattaDTO> regattas = getSelectedRegattas();
|
||||
createEventDetails(regattas);
|
||||
}
|
||||
});
|
||||
addButton.addClickHandler(new ClickHandler() {
|
||||
@@ -112,23 +86,17 @@ public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
removeButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
List<RegattaDTO> regattaDTOs = regattaListComposite.getAllRegattas();
|
||||
List<RegattaDTO> regattas = regattaListComposite.getAllRegattas();
|
||||
for (RegattaIdentifier selectedRegatta : regattaSelectionProvider.getSelectedRegattas()) {
|
||||
for (RegattaDTO regattaDTO : regattaListComposite.getAllRegattas()) {
|
||||
if (regattaDTO.getRegattaIdentifier().equals(selectedRegatta)) {
|
||||
regattaDTOs.remove(regattaDTO);
|
||||
regattas.remove(regattaDTO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fillRegattas(regattaDTOs);
|
||||
regattaDTOs.clear();
|
||||
}
|
||||
});
|
||||
refreshButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
refreshUrlList();
|
||||
fillRegattas(regattas);
|
||||
regattas.clear();
|
||||
}
|
||||
});
|
||||
VerticalPanel vp = new VerticalPanel();
|
||||
@@ -138,15 +106,13 @@ public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
buttonPanel.add(addButton);
|
||||
buttonPanel.add(importDetailsButton);
|
||||
buttonPanel.add(removeButton);
|
||||
// buttonPanel.add(refreshButton);
|
||||
Grid grid = new Grid(1, 1);
|
||||
vp.add(grid);
|
||||
|
||||
regattaSelectionProvider = new RegattaSelectionModel(true);
|
||||
// regattaSelectionProvider.addRegattaSelectionChangeListener(this);
|
||||
|
||||
regattaListComposite = new StructureImportListComposite(sailingService, regattaSelectionProvider,
|
||||
regattaRefresher, errorReporter, stringMessages, "test");
|
||||
regattaListComposite = new StructureImportListComposite(this.sailingService, regattaSelectionProvider,
|
||||
this.regattaRefresher, this.errorReporter, this.stringMessages, "test");
|
||||
regattaListComposite.ensureDebugId("RegattaListComposite");
|
||||
grid.setWidget(0, 0, regattaListComposite);
|
||||
grid.getRowFormatter().setVerticalAlign(0, HasVerticalAlignment.ALIGN_TOP);
|
||||
@@ -155,62 +121,18 @@ public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
|
||||
add(progressPanel);
|
||||
add(vp);
|
||||
refreshUrlList();
|
||||
|
||||
}
|
||||
|
||||
private String getSelectedProviderName() {
|
||||
String result = null;
|
||||
int selectedIndex = urlProviderSelectionListBox.getSelectedIndex();
|
||||
if (selectedIndex > 0) {
|
||||
result = urlProviderSelectionListBox.getItemText(selectedIndex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void refreshUrlList() {
|
||||
String selectedProviderName = getSelectedProviderName();
|
||||
if (selectedProviderName != null) {
|
||||
sailingService.getResultImportUrls(selectedProviderName, new AsyncCallback<List<String>>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
errorReporter.reportError(stringMessages.errorRefreshingResultImportUrlList(caught.getMessage()));
|
||||
private List<RegattaDTO> getSelectedRegattas() {
|
||||
List<RegattaDTO> regattas = new ArrayList<RegattaDTO>();
|
||||
for (RegattaIdentifier selectedRegatta : regattaSelectionProvider.getSelectedRegattas()) {
|
||||
for (RegattaDTO regattaDTO : regattaListComposite.getAllRegattas()) {
|
||||
if (regattaDTO.getRegattaIdentifier().equals(selectedRegatta)) {
|
||||
regattas.add(regattaDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<String> result) {
|
||||
urlListBox.clear();
|
||||
for (String s : result) {
|
||||
urlListBox.addItem(s);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
urlListBox.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void removeSelectedUrls() {
|
||||
Set<String> toRemove = new HashSet<String>();
|
||||
for (int i = urlListBox.getItemCount() - 1; i >= 0; i--) {
|
||||
if (urlListBox.isItemSelected(i)) {
|
||||
toRemove.add(urlListBox.getItemText(i));
|
||||
urlListBox.removeItem(i);
|
||||
}
|
||||
}
|
||||
String selectedProviderName = getSelectedProviderName();
|
||||
sailingService.removeResultImportURLs(selectedProviderName, toRemove, new AsyncCallback<Void>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
errorReporter.reportError(stringMessages.errorRemovingResultImportUrls(caught.getMessage()));
|
||||
refreshUrlList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
Window.setStatus(stringMessages.successfullyUpdatedResultImportUrls());
|
||||
}
|
||||
});
|
||||
return regattas;
|
||||
}
|
||||
|
||||
private void createEventDetails(List<RegattaDTO> regattas) {
|
||||
@@ -228,40 +150,7 @@ public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<EventDTO> events) {
|
||||
List<EventDTO> existingEvents = events;
|
||||
EventCreateDialog dialog = new EventCreateDialog(Collections.unmodifiableCollection(existingEvents),
|
||||
stringMessages, new DialogCallback<EventDTO>() {
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ok(final EventDTO newEvent) {
|
||||
List<String> courseAreaNames = new ArrayList<String>();
|
||||
for (CourseAreaDTO courseAreaDTO : newEvent.venue.getCourseAreas()) {
|
||||
courseAreaNames.add(courseAreaDTO.getName());
|
||||
}
|
||||
sailingService.createEvent(newEvent.getName(), newEvent.startDate, newEvent.endDate,
|
||||
newEvent.venue.getName(), newEvent.isPublic, courseAreaNames,
|
||||
newEvent.getImageURLs(), newEvent.getVideoURLs(),
|
||||
newEvent.getSponsorImageURLs(), newEvent.getLogoImageURL(),
|
||||
newEvent.getOfficialWebsiteURL(), new AsyncCallback<EventDTO>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
errorReporter.reportError("Error trying to create new event "
|
||||
+ newEvent.getName() + ": " + t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(EventDTO newEvent) {
|
||||
setDefaultRegatta(regattaNames, newEvent);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
openEventCreateDialog(regattaNames, events);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -310,16 +199,15 @@ public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
regattaListComposite.fillRegattas(regattas);
|
||||
}
|
||||
|
||||
private void createBarAndLabel(int amountOfRegattas) {
|
||||
private void createProgressBarAndLabel(int amountOfRegattas) {
|
||||
overallName = new Label(stringMessages.overallProgress() + ":");
|
||||
progressPanel.add(overallName);
|
||||
progressBar = new StructureImportProgressBar(amountOfRegattas + 1, Style.ANIMATED);
|
||||
progressPanel.add(progressBar);
|
||||
|
||||
}
|
||||
|
||||
private void setProgressBar(final int amountOfRegattas) {
|
||||
createBarAndLabel(amountOfRegattas);
|
||||
createProgressBarAndLabel(amountOfRegattas);
|
||||
|
||||
final Timer timer = new Timer() {
|
||||
@Override
|
||||
@@ -337,9 +225,10 @@ public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
}
|
||||
|
||||
});
|
||||
if (parsed >= amountOfRegattas) {
|
||||
if (parsed >= amountOfRegattas) { /*finished*/
|
||||
regattaRefresher.fillRegattas();
|
||||
fillRegattas(new ArrayList<RegattaDTO>());
|
||||
importDetailsButton.setEnabled(false);
|
||||
progressBar.removeFromParent();
|
||||
overallName.removeFromParent();
|
||||
this.cancel();
|
||||
@@ -372,7 +261,7 @@ public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
|
||||
private void createRegattas(final List<String> regattaNames, EventDTO newEvent, RegattaDTO defaultRegatta) {
|
||||
eventManagementPanel.fillEvents();
|
||||
sailingService.addEventImportUrl(regattaNames, newEvent, defaultRegatta, new AsyncCallback<Void>() {
|
||||
sailingService.createRegattaStructure(regattaNames, newEvent, defaultRegatta, new AsyncCallback<Void>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
errorReporter.reportError(stringMessages.errorAddingResultImportUrl(caught.getMessage()));
|
||||
@@ -385,4 +274,42 @@ public class StructureImportUrlsManagementPanel extends FlowPanel{
|
||||
});
|
||||
}
|
||||
|
||||
private void openEventCreateDialog(final List<String> regattaNames, List<EventDTO> events) {
|
||||
EventCreateDialog dialog = new EventCreateDialog(Collections.unmodifiableCollection(events), stringMessages,
|
||||
new DialogCallback<EventDTO>() {
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ok(final EventDTO newEvent) {
|
||||
createEventAndRegattaStructure(regattaNames, newEvent);
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void createEventAndRegattaStructure(final List<String> regattaNames, final EventDTO newEvent) {
|
||||
List<String> courseAreaNames = new ArrayList<String>();
|
||||
for (CourseAreaDTO courseAreaDTO : newEvent.venue.getCourseAreas()) {
|
||||
courseAreaNames.add(courseAreaDTO.getName());
|
||||
}
|
||||
sailingService.createEvent(newEvent.getName(), newEvent.startDate, newEvent.endDate, newEvent.venue.getName(),
|
||||
newEvent.isPublic, courseAreaNames, newEvent.getImageURLs(), newEvent.getVideoURLs(),
|
||||
newEvent.getSponsorImageURLs(), newEvent.getLogoImageURL(), newEvent.getOfficialWebsiteURL(),
|
||||
new AsyncCallback<EventDTO>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
errorReporter.reportError("Error trying to create new event " + newEvent.getName() + ": "
|
||||
+ t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(EventDTO newEvent) {
|
||||
setDefaultRegatta(regattaNames, newEvent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -341,7 +341,7 @@ public interface SailingService extends RemoteService {
|
||||
|
||||
List<RegattaDTO> getRegattas(String url);
|
||||
|
||||
void addEventImportUrl(List<String> regattaNames,EventDTO newEvent, RegattaDTO defaultRegatta);
|
||||
void createRegattaStructure(List<String> regattaNames,EventDTO newEvent, RegattaDTO defaultRegatta);
|
||||
|
||||
|
||||
void updateLeaderboardScoreCorrectionMetadata(String leaderboardName, Date timePointOfLastCorrectionValidity,
|
||||
|
||||
+1
-1
@@ -642,6 +642,6 @@ public interface SailingServiceAsync {
|
||||
|
||||
void getRegattas(String url, AsyncCallback<List<RegattaDTO>> asyncCallback);
|
||||
|
||||
void addEventImportUrl(List<String> regattaNames, EventDTO newEvent,RegattaDTO defaultRegatta, AsyncCallback<Void> asyncCallback);
|
||||
void createRegattaStructure(List<String> regattaNames, EventDTO newEvent,RegattaDTO defaultRegatta, AsyncCallback<Void> asyncCallback);
|
||||
|
||||
}
|
||||
|
||||
+24
-30
@@ -388,15 +388,13 @@ import com.sap.sailing.server.replication.impl.ReplicaDescriptor;
|
||||
import com.sap.sailing.util.BuildVersion;
|
||||
import com.sap.sailing.xrr.schema.RegattaResults;
|
||||
import com.sap.sailing.xrr.structureimport.SeriesParameters;
|
||||
import com.sap.sailing.xrr.structureimport.StructureImportUrl;
|
||||
import com.sap.sailing.xrr.structureimport.StructureImporter;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.Util.Pair;
|
||||
import com.sap.sse.common.Util.Triple;
|
||||
import com.sap.sse.common.search.KeywordQuery;
|
||||
import com.sap.sse.common.search.Result;
|
||||
|
||||
import eventimport.Regattas;
|
||||
|
||||
/**
|
||||
* The server side implementation of the RPC service.
|
||||
*/
|
||||
@@ -461,7 +459,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
|
||||
private final QuickRanksLiveCache quickRanksLiveCache;
|
||||
|
||||
private StructureImportUrl structureImport = null;
|
||||
private StructureImporter structureImporter = null;
|
||||
|
||||
public SailingServiceImpl() {
|
||||
BundleContext context = Activator.getDefault();
|
||||
@@ -3736,21 +3734,19 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
}
|
||||
|
||||
public List<RegattaDTO> getRegattas(String url) {
|
||||
structureImport = new StructureImportUrl(url, new SetRacenumberFromSeries());
|
||||
RegattaDTO regattaDTO = null;
|
||||
ArrayList<Regattas> regattas = structureImport.getRegattas();
|
||||
List<RegattaDTO> regattasDTO = new ArrayList<RegattaDTO>();
|
||||
for (int i = 0; i < regattas.size(); i++) {
|
||||
regattaDTO = new RegattaDTO(regattas.get(i).getName(), null);
|
||||
regattasDTO.add(regattaDTO);
|
||||
structureImporter = new StructureImporter(url, new SetRacenumberFromSeries());
|
||||
List<RegattaDTO> dummyRegattaDTOs = new ArrayList<RegattaDTO>();
|
||||
List<String> regattaNames = structureImporter.getRegattaNames();
|
||||
for (String regattaName : regattaNames) {
|
||||
dummyRegattaDTOs.add(new RegattaDTO(regattaName, null));
|
||||
}
|
||||
return regattasDTO;
|
||||
return dummyRegattaDTOs;
|
||||
}
|
||||
|
||||
private ArrayList<String> createRegattasWithRaces(ArrayList<AddSpecificRegatta> regattas, String eventName) {
|
||||
|
||||
ArrayList<String> leaderboardNames = new ArrayList<String>();
|
||||
List<List<List<String>>> series = structureImport.getRaceNames();
|
||||
List<List<List<String>>> series = structureImporter.getRaceNames();
|
||||
|
||||
for (int i = 0; i < regattas.size(); i++) {
|
||||
Regatta regatta = getService().apply(regattas.get(i));
|
||||
@@ -3771,7 +3767,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventImportUrl(final List<String> regattaNames, final EventDTO newEvent,
|
||||
public void createRegattaStructure(final List<String> regattaNames, final EventDTO newEvent,
|
||||
final RegattaDTO defaultRegatta) {
|
||||
|
||||
Runnable structureImportTask = new Runnable() {
|
||||
@@ -3779,40 +3775,39 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
structureImport.updateRegattasToSelected(regattaNames);
|
||||
structureImporter.updateRegattasToSelected(regattaNames);
|
||||
|
||||
// set default settings for series
|
||||
SeriesParameters defaultSeries = getDefaultSeries(defaultRegatta);
|
||||
|
||||
// get Regattas
|
||||
ArrayList<AddSpecificRegatta> regattas = structureImport.getRegattas(defaultRegatta.scoringScheme,
|
||||
ArrayList<AddSpecificRegatta> regattas = structureImporter.getRegattas(defaultRegatta.scoringScheme,
|
||||
false, defaultRegatta.defaultCourseAreaUuid, defaultRegatta.useStartTimeInference,
|
||||
getBaseDomainFactory(), defaultSeries.isFirstColumnIsNonDiscardableCarryForward(),
|
||||
defaultSeries.isHasSplitFleetContiguousScoring(), defaultSeries.isStartswithZeroScore(),
|
||||
defaultSeries.getDiscardingThresholds());
|
||||
|
||||
String eventName = structureImport.getEventName();
|
||||
ArrayList<String> leaderboardNames = createRegattasWithRaces(regattas, eventName);
|
||||
// create Leaderboard Group
|
||||
createAndAddLeaderboardGroup(newEvent, eventName, leaderboardNames);
|
||||
structureImport.setCompetitors();
|
||||
structureImport.resetSeriesForRegattas();
|
||||
structureImport.setFinished(true);
|
||||
ArrayList<String> leaderboardNames = createRegattasWithRaces(regattas, newEvent.getName());
|
||||
createAndAddLeaderboardGroup(newEvent, leaderboardNames);
|
||||
structureImporter.setCompetitors();
|
||||
structureImporter.resetSeriesForRegattas();
|
||||
structureImporter.setFinished(true);
|
||||
|
||||
}
|
||||
};
|
||||
executor.execute(structureImportTask);
|
||||
}
|
||||
|
||||
private void createAndAddLeaderboardGroup(final EventDTO newEvent, String eventName,
|
||||
private void createAndAddLeaderboardGroup(final EventDTO newEvent,
|
||||
ArrayList<String> leaderboardNames) {
|
||||
LeaderboardGroupDTO leaderboardGroupDTO = null;
|
||||
String description = "";
|
||||
if(newEvent.getDescription()!=null){
|
||||
description = newEvent.getDescription();
|
||||
}
|
||||
String eventName = newEvent.getName();
|
||||
|
||||
// create Leaderboard Group
|
||||
if(getService().getLeaderboardGroupByName(newEvent.getName())==null){
|
||||
if(getService().getLeaderboardGroupByName(eventName)==null){
|
||||
CreateLeaderboardGroup createLeaderboardGroupOp = new CreateLeaderboardGroup(eventName,
|
||||
description, eventName, false, leaderboardNames, null, null);
|
||||
leaderboardGroupDTO = convertToLeaderboardGroupDTO(getService().apply(createLeaderboardGroupOp), false,
|
||||
@@ -3834,7 +3829,6 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
newEvent.getLogoImageURL(), newEvent.getOfficialWebsiteURL(), newEvent.getImageURLs(),
|
||||
newEvent.getVideoURLs(), newEvent.getSponsorImageURLs());
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -4437,9 +4431,9 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
|
||||
public Integer getStructureImportOperationProgress() {
|
||||
int parsedDocuments = 0;
|
||||
if (structureImport != null) {
|
||||
parsedDocuments = structureImport.getProgress();
|
||||
if (structureImport.isFinished()) {
|
||||
if (structureImporter != null) {
|
||||
parsedDocuments = structureImporter.getProgress();
|
||||
if (structureImporter.isFinished()) {
|
||||
parsedDocuments++;
|
||||
}
|
||||
}
|
||||
|
||||
+87
-74
@@ -48,61 +48,60 @@ import com.sap.sailing.xrr.schema.RegattaResults;
|
||||
import com.sap.sailing.xrr.schema.Team;
|
||||
|
||||
import eventimport.EventImport;
|
||||
import eventimport.Regattas;
|
||||
import eventimport.RegattaJSON;
|
||||
|
||||
public class StructureImportUrl {
|
||||
public class StructureImporter {
|
||||
|
||||
private ArrayList<RegattaResults> results = new ArrayList<RegattaResults>();
|
||||
private String eventName = "";
|
||||
private static List<List<List<String>>> seriesForRegattas = new ArrayList<List<List<String>>>();
|
||||
private ArrayList<Regattas> regattas;
|
||||
private ArrayList<RegattaJSON> regattas;
|
||||
private LinkedHashMap<String, Boat> boatForPerson;
|
||||
private DomainFactory baseDomainFactory;
|
||||
private SetRacenumberStrategy setRacenumberStrategy;
|
||||
private int parsedDocuments = 0;
|
||||
private boolean finished = false;
|
||||
|
||||
public StructureImportUrl(String url, SetRacenumberStrategy setRacenumber) {
|
||||
public StructureImporter(String url, SetRacenumberStrategy setRacenumber) {
|
||||
|
||||
this.setRacenumberStrategy = setRacenumber;
|
||||
regattas = new EventImport().getRegattas(url);
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Regattas> getRegattas() {
|
||||
return regattas;
|
||||
public List<String> getRegattaNames() {
|
||||
List<String> regattaNames = new ArrayList<String>();
|
||||
for (RegattaJSON regatta : regattas) {
|
||||
regattaNames.add(regatta.getName());
|
||||
}
|
||||
return regattaNames;
|
||||
}
|
||||
|
||||
public void updateRegattasToSelected(List<String> regattaNames) {
|
||||
ArrayList<Regattas> regattasTemp = new ArrayList<Regattas>();
|
||||
for (Regattas regatta : regattas) {
|
||||
List<RegattaJSON> regattasTemp = new ArrayList<RegattaJSON>(regattas);
|
||||
regattas.clear();
|
||||
for (RegattaJSON regatta : regattasTemp) {
|
||||
for (String s : regattaNames) {
|
||||
if (regatta.getName().equals(s)) {
|
||||
regattasTemp.add(regatta);
|
||||
regattas.add(regatta);
|
||||
}
|
||||
}
|
||||
}
|
||||
regattas = regattasTemp;
|
||||
}
|
||||
|
||||
public void parseEvent() {
|
||||
private void parseRegattas() {
|
||||
|
||||
for (int i = 0; i < regattas.size(); i++) {
|
||||
try {
|
||||
parseRegattaXML(regattas.get(i).getXrrEntriesUrl());
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (JAXBException e) {
|
||||
// TODO Auto-generated catch blocks
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
parsedDocuments++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<AddSpecificRegatta> getRegattas(ScoringSchemeType scoringScheme, boolean isPersistent,
|
||||
@@ -112,15 +111,14 @@ public class StructureImportUrl {
|
||||
|
||||
this.baseDomainFactory = baseDomainFactory;
|
||||
ArrayList<AddSpecificRegatta> regattas = new ArrayList<AddSpecificRegatta>();
|
||||
Event event = null;
|
||||
results.clear();
|
||||
parseEvent();
|
||||
parseRegattas();
|
||||
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
|
||||
ArrayList<Race> races = new ArrayList<Race>();
|
||||
|
||||
event = (Event) results.get(i).getPersonOrBoatOrTeam()
|
||||
Event event = (Event) results.get(i).getPersonOrBoatOrTeam()
|
||||
.get(results.get(i).getPersonOrBoatOrTeam().size() - 1);
|
||||
|
||||
List<Object> raceOrDevisionOrRegattaSeries = event.getRaceOrDivisionOrRegattaSeriesResult();
|
||||
@@ -130,7 +128,7 @@ public class StructureImportUrl {
|
||||
|
||||
BuildStructure structure = new BuildStructure(races);
|
||||
|
||||
LinkedHashMap<String, SeriesCreationParametersDTO> seriesCreationParams = setSeriesCreationParametersDTO(
|
||||
LinkedHashMap<String, SeriesCreationParametersDTO> seriesCreationParams = setSeriesCreationParameters(
|
||||
structure, firstColumnIsNonDiscardableCarryForward, hasSplitFleetContiguousScoring,
|
||||
startswithZeroScore, discardingThresholds);
|
||||
|
||||
@@ -141,15 +139,10 @@ public class StructureImportUrl {
|
||||
.createScoringScheme(scoringScheme), courseArea, useStartTimeInference));
|
||||
|
||||
}
|
||||
eventName = event.getTitle();
|
||||
return regattas;
|
||||
}
|
||||
|
||||
public String getEventName() {
|
||||
return eventName;
|
||||
}
|
||||
|
||||
private LinkedHashMap<String, SeriesCreationParametersDTO> setSeriesCreationParametersDTO(BuildStructure structure,
|
||||
private LinkedHashMap<String, SeriesCreationParametersDTO> setSeriesCreationParameters(BuildStructure structure,
|
||||
boolean firstColumnIsNonDiscardableCarryForward, boolean hasSplitFleetContiguousScoring,
|
||||
boolean startswithZeroScore, int[] discardingThresholds) {
|
||||
LinkedHashMap<String, SeriesCreationParametersDTO> seriesCreationParams = new LinkedHashMap<String, SeriesCreationParametersDTO>();
|
||||
@@ -163,31 +156,11 @@ public class StructureImportUrl {
|
||||
|
||||
RaceType raceType = raceTypes.get(i);
|
||||
|
||||
ArrayList<Fleet> fleets = raceType.getFleets();
|
||||
ArrayList<FleetDTO> fleetsDTO = new ArrayList<FleetDTO>();
|
||||
String fleetColor;
|
||||
for (int j = 0; j < fleets.size(); j++) {
|
||||
if (fleets.size() <= 1) {
|
||||
fleetColor = "Default";
|
||||
} else {
|
||||
fleetColor = fleets.get(j).getColor();
|
||||
}
|
||||
|
||||
FleetDTO fleetDTO = new FleetDTO(fleetColor, j, getColorFromString(fleetColor));
|
||||
fleetsDTO.add(fleetDTO);
|
||||
}
|
||||
List<String> raceNames = new ArrayList<String>();
|
||||
raceNames.clear();
|
||||
|
||||
// set Racenumbers for each series
|
||||
Race[] races = fleets.get(raceType.getMaxIndex()).getRaces();
|
||||
for (int j = 0; j < races.length; j++) {
|
||||
Race race = races[j];
|
||||
setRacenumberStrategy.setRacenumber(race, raceType, i, raceNames);
|
||||
}
|
||||
ArrayList<FleetDTO> fleets = getFleets(raceType.getFleets());
|
||||
List<String> raceNames = getRaceNames(i, raceType, raceType.getFleets());
|
||||
series.add(raceNames);
|
||||
|
||||
seriesCreationParams.put(raceType.getRaceType(), new SeriesCreationParametersDTO(fleetsDTO,
|
||||
seriesCreationParams.put(raceType.getRaceType(), new SeriesCreationParametersDTO(fleets,
|
||||
/* medal */raceTypes.get(i).isMedal(), startswithZeroScore, firstColumnIsNonDiscardableCarryForward,
|
||||
discardingThresholds, hasSplitFleetContiguousScoring));
|
||||
}
|
||||
@@ -198,9 +171,38 @@ public class StructureImportUrl {
|
||||
|
||||
}
|
||||
|
||||
private List<String> getRaceNames(int i, RaceType raceType, ArrayList<Fleet> fleets) {
|
||||
List<String> raceNames = new ArrayList<String>();
|
||||
raceNames.clear();
|
||||
|
||||
// set Racenumbers for each series
|
||||
Race[] races = fleets.get(raceType.getMaxIndex()).getRaces();
|
||||
for (int j = 0; j < races.length; j++) {
|
||||
Race race = races[j];
|
||||
setRacenumberStrategy.setRacenumber(race, raceType, i, raceNames);
|
||||
}
|
||||
return raceNames;
|
||||
}
|
||||
|
||||
private ArrayList<FleetDTO> getFleets(ArrayList<Fleet> fleets) {
|
||||
ArrayList<FleetDTO> fleetsDTO = new ArrayList<FleetDTO>();
|
||||
String fleetColor;
|
||||
for (int j = 0; j < fleets.size(); j++) {
|
||||
if (fleets.size() <= 1) {
|
||||
fleetColor = "Default";
|
||||
} else {
|
||||
fleetColor = fleets.get(j).getColor();
|
||||
}
|
||||
|
||||
FleetDTO fleetDTO = new FleetDTO(fleetColor, j, getColorFromString(fleetColor));
|
||||
fleetsDTO.add(fleetDTO);
|
||||
}
|
||||
return fleetsDTO;
|
||||
}
|
||||
|
||||
private Color getColorFromString(String colorString) {
|
||||
Color color = null;
|
||||
|
||||
|
||||
switch (colorString) {
|
||||
case "Blue":
|
||||
color = Color.BLUE;
|
||||
@@ -238,19 +240,15 @@ public class StructureImportUrl {
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
BoatClass boatClass = null;
|
||||
|
||||
if (regattas.get(i).getBoatClass() != null) {
|
||||
boatClass = baseDomainFactory.getOrCreateBoatClass(regattas.get(i).getBoatClass());
|
||||
} else {
|
||||
boatClass = baseDomainFactory.getOrCreateBoatClass("default");
|
||||
}
|
||||
boatClass = getBoatClass(regattas.get(i));
|
||||
|
||||
ArrayList<Object> personOrBoatOrTeam = (ArrayList<Object>) results.get(i).getPersonOrBoatOrTeam();
|
||||
|
||||
setBoatsAndTeamsForPerson(personOrBoatOrTeam);
|
||||
|
||||
for (int j = 0; j < personOrBoatOrTeam.size(); j++) {
|
||||
if (personOrBoatOrTeam.get(j) instanceof Person) {
|
||||
Person person = (Person) personOrBoatOrTeam.get(j);
|
||||
for (Object obj : personOrBoatOrTeam) {
|
||||
if (obj instanceof Person) {
|
||||
Person person = (Person) obj;
|
||||
String idAsString = person.getPersonID();
|
||||
|
||||
String name = person.getGivenName() + " " + person.getFamilyName();
|
||||
@@ -270,6 +268,16 @@ public class StructureImportUrl {
|
||||
|
||||
}
|
||||
|
||||
private BoatClass getBoatClass(RegattaJSON regatta) {
|
||||
BoatClass boatClass;
|
||||
if (regatta.getBoatClass() != null) {
|
||||
boatClass = baseDomainFactory.getOrCreateBoatClass(regatta.getBoatClass());
|
||||
} else {
|
||||
boatClass = baseDomainFactory.getOrCreateBoatClass("default");
|
||||
}
|
||||
return boatClass;
|
||||
}
|
||||
|
||||
private Nationality getNationality(String country) {
|
||||
return baseDomainFactory.getOrCreateNationality(country);
|
||||
}
|
||||
@@ -279,19 +287,19 @@ public class StructureImportUrl {
|
||||
boatForPerson = new LinkedHashMap<String, Boat>();
|
||||
LinkedHashMap<String, Team> teamForBoat = new LinkedHashMap<String, Team>();
|
||||
|
||||
for (int i = 0; i < personOrBoatOrTeam.size(); i++) {
|
||||
if (personOrBoatOrTeam.get(i) instanceof Team) {
|
||||
teamForBoat.put(((Team) personOrBoatOrTeam.get(i)).getBoatID(), (Team) personOrBoatOrTeam.get(i));
|
||||
for (Object obj : personOrBoatOrTeam){
|
||||
if (obj instanceof Team) {
|
||||
teamForBoat.put(((Team) obj).getBoatID(), (Team) obj);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < personOrBoatOrTeam.size(); i++) {
|
||||
if (personOrBoatOrTeam.get(i) instanceof Boat) {
|
||||
Team team = teamForBoat.get(((Boat) personOrBoatOrTeam.get(i)).getBoatID());
|
||||
for (Object obj : personOrBoatOrTeam){
|
||||
if (obj instanceof Boat) {
|
||||
Team team = teamForBoat.get(((Boat) obj).getBoatID());
|
||||
|
||||
ArrayList<Crew> crew = (ArrayList<Crew>) team.getCrew();
|
||||
for (int j = 0; j < crew.size(); j++) {
|
||||
boatForPerson.put(crew.get(j).getPersonID(), (Boat) personOrBoatOrTeam.get(i));
|
||||
for (Crew person : crew) {
|
||||
boatForPerson.put(person.getPersonID(), (Boat) obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,19 +310,24 @@ public class StructureImportUrl {
|
||||
|
||||
DynamicBoat boat = createBoat(name, boatForPerson.get(idAsString), boatClass);
|
||||
if (nationality == null) {
|
||||
String country = "";
|
||||
if (boat.getSailID().length() >= 3) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
country += boat.getSailID().charAt(i);
|
||||
}
|
||||
|
||||
nationality = getNationality(country);
|
||||
}
|
||||
nationality = createNationalityFromSailID(boat.getSailID());
|
||||
}
|
||||
DynamicTeam team = createTeam(name, nationality);
|
||||
return new BoatAndTeam(boat, team);
|
||||
}
|
||||
|
||||
private Nationality createNationalityFromSailID(String sailID) {
|
||||
String country = "";
|
||||
if (sailID.length() >= 3) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
country += sailID.charAt(i);
|
||||
}
|
||||
|
||||
return getNationality(country);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private DynamicBoat createBoat(String name, Boat boat, BoatClass boatClass) {
|
||||
|
||||
DynamicBoat boat1 = new BoatImpl(name + " boat", boatClass, boat.getSailNumber());
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
|
||||
public class EventImport {
|
||||
|
||||
public ArrayList<Regattas> getRegattas(String url){
|
||||
public ArrayList<RegattaJSON> getRegattas(String url){
|
||||
|
||||
EventResults results = new EventParser().parseEvent(url);
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ public class EventParser {
|
||||
|
||||
JSONObject jsonRoot;
|
||||
try {
|
||||
InputStreamReader is = new InputStreamReader(getStreamReader(url), "UTF-8");
|
||||
InputStreamReader streamReader = getStreamReader(url);
|
||||
|
||||
jsonRoot = (JSONObject) new JSONParser().parse(is);
|
||||
jsonRoot = (JSONObject) new JSONParser().parse(streamReader);
|
||||
eventResults = new EventResults();
|
||||
eventResults.setId((String) jsonRoot.get("Id"));
|
||||
eventResults.setName((String) jsonRoot.get("Name"));
|
||||
@@ -32,60 +32,49 @@ public class EventParser {
|
||||
|
||||
JSONArray jsonRegattas = (JSONArray) jsonRoot.get("Regattas");
|
||||
for (Object regattaObject: jsonRegattas) {
|
||||
Regattas regattas = new Regattas();
|
||||
RegattaJSON regatta = new RegattaJSON();
|
||||
JSONObject jsonRegatta = (JSONObject) regattaObject;
|
||||
regattas.setId((String) jsonRegatta.get("Id"));
|
||||
regattas.setName((String) jsonRegatta.get("Name"));
|
||||
regattas.setBoatClass((String) jsonRegatta.get("ClassName"));
|
||||
regattas.setGender((String) jsonRegatta.get("Gender"));
|
||||
regattas.setXrrEntriesUrl((String) jsonRegatta.get("XrrEntriesUrl"));
|
||||
regattas.setXrrPreliminaryUrl((String) jsonRegatta.get("XrrPreliminaryUrl"));
|
||||
regattas.setXrrFinalUrl((String) jsonRegatta.get("XrrFinalUrl"));
|
||||
regattas.setHtmlUrl((String) jsonRegatta.get("HtmlUrl"));
|
||||
regatta.setId((String) jsonRegatta.get("Id"));
|
||||
regatta.setName((String) jsonRegatta.get("Name"));
|
||||
regatta.setBoatClass((String) jsonRegatta.get("ClassName"));
|
||||
regatta.setGender((String) jsonRegatta.get("Gender"));
|
||||
regatta.setXrrEntriesUrl((String) jsonRegatta.get("XrrEntriesUrl"));
|
||||
regatta.setXrrPreliminaryUrl((String) jsonRegatta.get("XrrPreliminaryUrl"));
|
||||
regatta.setXrrFinalUrl((String) jsonRegatta.get("XrrFinalUrl"));
|
||||
regatta.setHtmlUrl((String) jsonRegatta.get("HtmlUrl"));
|
||||
|
||||
eventResults.addRegatta(regattas);
|
||||
eventResults.addRegatta(regatta);
|
||||
|
||||
}
|
||||
|
||||
is.close();
|
||||
streamReader.close();
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return eventResults;
|
||||
}
|
||||
|
||||
private InputStream getStreamReader(String url){
|
||||
private InputStreamReader getStreamReader(String url) throws UnsupportedEncodingException{
|
||||
|
||||
InputStream is = null;
|
||||
|
||||
URLConnection connection = null;
|
||||
try {
|
||||
connection = new URL(url).openConnection();
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
is = connection.getInputStream();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return is;
|
||||
return new InputStreamReader(is, "UTF-8");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,21 +4,21 @@ import java.util.ArrayList;
|
||||
|
||||
public class EventResults {
|
||||
|
||||
private ArrayList<Regattas> regattas = new ArrayList<Regattas>();
|
||||
private ArrayList<RegattaJSON> regattas = new ArrayList<RegattaJSON>();
|
||||
private String id = "";
|
||||
private String name = "";
|
||||
private String xrrUrl = "";
|
||||
|
||||
|
||||
public ArrayList<Regattas> getRegattas() {
|
||||
public ArrayList<RegattaJSON> getRegattas() {
|
||||
return regattas;
|
||||
}
|
||||
|
||||
public void setRegattas(ArrayList<Regattas> regattas) {
|
||||
public void setRegattas(ArrayList<RegattaJSON> regattas) {
|
||||
this.regattas = regattas;
|
||||
}
|
||||
|
||||
public void addRegatta(Regattas regatta){
|
||||
public void addRegatta(RegattaJSON regatta){
|
||||
this.regattas.add(regatta);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package eventimport;
|
||||
|
||||
public class Regattas {
|
||||
public class RegattaJSON {
|
||||
|
||||
private String id = "";
|
||||
private String name = "";
|
||||
@@ -19,6 +19,7 @@ lennart: lennart,spectator,moderator,administrator
|
||||
marcus: marcus,spectator,moderator,eventmanager
|
||||
milan: milan,spectator,moderator,administrator
|
||||
nils: nils,spectator,moderator,administrator
|
||||
nilsClient: nils,spectator
|
||||
stefan: stefan,spectator,moderator,administrator
|
||||
riccardo: riccardo,spectator,moderator,administrator
|
||||
christopher: christopher,spectator,moderator,administrator
|
||||
|
||||
Reference in New Issue
Block a user