use of com.cpjd.roblu.models.RForm in project Roblu by wdavies973.
the class EventMergeTask method run.
@Override
public void run() {
try {
// Load teams for each event
RTeam[] localTeams = io.loadTeams(localEventID);
RTeam[] targetTeams = io.loadTeams(targetEventID);
RForm localForm = io.loadForm(localEventID);
RForm targetForm = io.loadForm(targetEventID);
for (RTeam team : localTeams) team.verify(localForm);
for (RTeam team : targetTeams) team.verify(targetForm);
// Start merging
for (RTeam local : localTeams) {
// Find the team
for (RTeam target : targetTeams) {
if (local.getNumber() == target.getNumber()) {
for (RTab localTab : local.getTabs()) {
// Find tab
for (RTab targetTab : target.getTabs()) {
if (targetTab.getTitle().equalsIgnoreCase(localTab.getTitle())) {
// Match found, start merging metrics
for (RMetric localMetric : localTab.getMetrics()) {
// Find metric
for (RMetric targetMetric : targetTab.getMetrics()) {
/*
* Okay, the forms might be different, so we need to run some checks before we override the localMetric:
* -Same instanceof type (obviously)
* -Same title (within reason, do a little trimming, and ignore caps)
* -ID - ID should not be considered, they might not be equal
*
* If we find a good candidate for the metric, override the local. Conditions
* -Target is not modified: do nothing
* -Target is modified: overwrite if local not modified
* -Both modified: Compare team last edit time stamp
*/
if ((localMetric.getClass().equals(targetMetric.getClass())) && localMetric.getTitle().toLowerCase().replaceAll(" ", "").equals(targetMetric.getTitle().toLowerCase().replaceAll(" ", ""))) {
if (localMetric instanceof RGallery) {
// Just add the images
if (((RGallery) localMetric).getPictureIDs() == null)
((RGallery) localMetric).setPictureIDs(new ArrayList<Integer>());
if (((RGallery) localMetric).getImages() != null) {
// Add images to the current gallery
for (int i = 0; i < ((RGallery) targetMetric).getImages().size(); i++) {
((RGallery) localMetric).getPictureIDs().add(io.savePicture(localEventID, ((RGallery) targetMetric).getImages().get(i)));
}
}
// Don't forget to clear the pictures from memory after they've been merged
((RGallery) targetMetric).setImages(null);
local.setLastEdit(target.getLastEdit());
} else // Alright, looks like we can do the checks now
if (targetMetric.isModified() && !localMetric.isModified()) {
int tabIndex = local.getTabs().indexOf(localTab);
int metricIndex = local.getTabs().get(tabIndex).getMetrics().indexOf(localMetric);
local.getTabs().get(tabIndex).getMetrics().set(metricIndex, targetMetric);
local.setLastEdit(target.getLastEdit());
} else if (targetMetric.isModified() && localMetric.isModified() && target.getLastEdit() > local.getLastEdit()) {
int tabIndex = local.getTabs().indexOf(localTab);
int metricIndex = local.getTabs().get(tabIndex).getMetrics().indexOf(localMetric);
local.getTabs().get(tabIndex).getMetrics().set(metricIndex, targetMetric);
local.setLastEdit(target.getLastEdit());
}
break;
}
}
}
break;
}
}
}
break;
}
}
io.saveTeam(localEventID, local);
}
listener.success();
} catch (Exception e) {
Log.d("RBS", "Error occurred in EventMergeTask: " + e.getMessage());
listener.error();
}
}
use of com.cpjd.roblu.models.RForm in project Roblu by wdavies973.
the class Utils method createEmpty.
/**
* Creates an empty form for an event (not technically empty).
*
* Makes sure that nothing is null and that we have the required
* team name and team number fields
* @return creates an empty RForm
*/
public static RForm createEmpty() {
ArrayList<RMetric> pit = new ArrayList<>();
ArrayList<RMetric> matches = new ArrayList<>();
RTextfield name = new RTextfield(0, "Team name", false, true, "");
RTextfield number = new RTextfield(1, "Team number", true, true, "");
pit.add(name);
pit.add(number);
return new RForm(pit, matches);
}
use of com.cpjd.roblu.models.RForm in project Roblu by wdavies973.
the class IO method duplicateEvent.
/**
* Duplicates an event. The EVENT MUST BE RELOADED, never ever return the REvent
* reference.
* @param event the REvent to duplicate
* @param keepScoutingData true if scouting data should be preserved
* @return reference to the duplicated event
*/
public REvent duplicateEvent(REvent event, boolean keepScoutingData) {
int newID = getNewEventID();
// New name
event.setName("Copy of " + event.getName());
// Set teams
RTeam[] teams = loadTeams(event.getID());
// Set forms
RForm form = loadForm(event.getID());
event.setID(newID);
saveEvent(event);
saveForm(newID, form);
RTeam temp;
for (int i = 0; teams != null && i < teams.length; i++) {
temp = teams[i];
if (!keepScoutingData)
temp.setTabs(null);
temp.setPage(1);
saveTeam(newID, temp);
}
return event;
}
Aggregations