item.setId(itemId);
item = (Item)findById(item, em, context);
newParent = (Sprint)PmSprint.instance().findById(newParent, em, context);
Sprint oldParent = null;
ItemImplementation moved = null;
if (iiId != null) {
moved = PmItemImplementation.instance().findById(iiId, em, context);
if (moved != null) {
oldParent = moved.getSprint();
for (ItemImplementation ii : oldParent.getItemImplementation()) {
if (ii.getNextId() != null &&
moved.getId() != null && ii.getNextId().longValue() == moved.getId().longValue()) {
ii.setNextId(moved.getNextId());
persist(ii, em, context);
break;
}
}
}
if (oldParent != null && oldParent.getId().longValue() != newParent.getId().longValue()) {
oldParent.getItemImplementation().remove(moved);
}
}
Long nextId = null;
if (moved != null) {
for (ItemImplementation ii : newParent.getItemImplementation()) {
if (before != null && ii.getItem().getId().longValue() == before.longValue()) {
nextId = ii.getId();
break;
}
}
for (ItemImplementation ii : newParent.getItemImplementation()) {
if (nextId != null && ii.getNextId() != null && ii.getNextId().longValue() == nextId.longValue()) {
ii.setNextId(moved.getId());
persist(ii, em, context);
break;
}
}
moved.setNextId(nextId);
if (before == null && newParent.getFirstItemImplementation() != null) {
moved.setNextId(newParent.getFirstItemImplementation().getId());
}
if (oldParent.getId().longValue() != newParent.getId().longValue()) {
newParent.getItemImplementation().add(moved);
moved.setSprint(newParent);
}
persist(moved, em, context);