ItEr43S09ImplantacionAplicacionItEr42S13: [Bug #241] Fixing bug. Initializing labels when being retrieved.

The problem was that the data bindings were retrieving the labels
before being initialized.
This commit is contained in:
Óscar González Fernández 2010-01-16 18:56:16 +01:00
parent 5b1ee5588c
commit f2522839ad
3 changed files with 10 additions and 3 deletions

View file

@ -123,6 +123,7 @@ public class OrderModel implements IOrderModel {
private IOrderSequenceDAO orderSequenceDAO;
@Override
@Transactional(readOnly = true)
public List<Label> getLabels() {
return getLabelsOnConversation().getLabels();
}

View file

@ -180,6 +180,7 @@ public abstract class AssignedLabelsModel<T> implements IAssignedLabelsModel<T>
return false;
}
@Transactional(readOnly = true)
public List<Label> getAllLabels() {
return getLabelsOnConversation();
}

View file

@ -37,28 +37,32 @@ public class LabelsOnConversation {
private final ILabelDAO labelDAO;
private Set<Label> labels = new HashSet<Label>();
private Set<Label> labels = null;
public LabelsOnConversation(ILabelDAO labelDAO) {
this.labelDAO = labelDAO;
}
public List<Label> getLabels() {
if (labels == null) {
initializeLabels();
}
return new ArrayList<Label>(labels);
}
public void addLabel(Label label) {
initializeLabels();
Validate.notNull(label);
labels.add(label);
}
public void initializeLabels() {
if (!labels.isEmpty()) {
if (this.labels != null) {
return;
}
final List<Label> labels = labelDAO.getAll();
initializeLabels(labels);
labels.addAll(labels);
this.labels = new HashSet<Label>(labels);
}
private void initializeLabels(Collection<Label> labels) {
@ -73,6 +77,7 @@ public class LabelsOnConversation {
}
public void reattachLabels() {
initializeLabels();
for (Label each : labels) {
labelDAO.reattach(each);
}