|
Lines 821-840
Link Here
|
| 821 |
} |
821 |
} |
| 822 |
|
822 |
|
| 823 |
public static TaskListNotificationIncoming getIncommingNotification(AbstractRepositoryConnector connector, |
823 |
public static TaskListNotificationIncoming getIncommingNotification(AbstractRepositoryConnector connector, |
| 824 |
AbstractTask repositoryTask) { |
824 |
AbstractTask task) { |
| 825 |
|
825 |
|
| 826 |
TaskListNotificationIncoming notification = new TaskListNotificationIncoming(repositoryTask); |
826 |
TaskListNotificationIncoming notification = new TaskListNotificationIncoming(task); |
| 827 |
RepositoryTaskData newTaskData = getTaskDataManager().getNewTaskData(repositoryTask.getRepositoryUrl(), |
827 |
RepositoryTaskData newTaskData = getTaskDataManager().getNewTaskData(task.getRepositoryUrl(), task.getTaskId()); |
| 828 |
repositoryTask.getTaskId()); |
828 |
RepositoryTaskData oldTaskData = getTaskDataManager().getOldTaskData(task.getRepositoryUrl(), task.getTaskId()); |
| 829 |
RepositoryTaskData oldTaskData = getTaskDataManager().getOldTaskData(repositoryTask.getRepositoryUrl(), |
|
|
| 830 |
repositoryTask.getTaskId()); |
| 831 |
|
829 |
|
| 832 |
if (newTaskData != null && oldTaskData != null) { |
830 |
if (newTaskData != null && oldTaskData != null) { |
| 833 |
|
831 |
|
| 834 |
String descriptionText = getChangedDescription(newTaskData, oldTaskData); |
832 |
notification.setDescription(getChangedDescription(newTaskData, oldTaskData)); |
| 835 |
if (descriptionText != null) { |
833 |
notification.setDetails(getChangedAttributes(newTaskData, oldTaskData)); |
| 836 |
notification.setDescription(descriptionText); |
|
|
| 837 |
} |
| 838 |
|
834 |
|
| 839 |
if (connector != null) { |
835 |
if (connector != null) { |
| 840 |
AbstractTaskDataHandler offlineHandler = connector.getTaskDataHandler(); |
836 |
AbstractTaskDataHandler offlineHandler = connector.getTaskDataHandler(); |
|
Lines 852-858
Link Here
|
| 852 |
} |
848 |
} |
| 853 |
|
849 |
|
| 854 |
private static String getChangedDescription(RepositoryTaskData newTaskData, RepositoryTaskData oldTaskData) { |
850 |
private static String getChangedDescription(RepositoryTaskData newTaskData, RepositoryTaskData oldTaskData) { |
| 855 |
|
|
|
| 856 |
String descriptionText = ""; |
851 |
String descriptionText = ""; |
| 857 |
|
852 |
|
| 858 |
if (newTaskData.getComments().size() > oldTaskData.getComments().size()) { |
853 |
if (newTaskData.getComments().size() > oldTaskData.getComments().size()) { |
|
Lines 870-898
Link Here
|
| 870 |
} |
865 |
} |
| 871 |
} |
866 |
} |
| 872 |
|
867 |
|
| 873 |
boolean attributeChanged = false; |
868 |
if (descriptionText.equals("")) { |
|
|
869 |
String attributes = getChangedAttributes(newTaskData, oldTaskData); |
| 870 |
if(!attributes.equals("")) { |
| 871 |
descriptionText += "Attributes changed"; |
| 872 |
} |
| 873 |
} |
| 874 |
|
| 875 |
return descriptionText; |
| 876 |
} |
| 874 |
|
877 |
|
|
|
878 |
private static String getChangedAttributes(RepositoryTaskData newTaskData, RepositoryTaskData oldTaskData) { |
| 879 |
List<Change> changes = new ArrayList<Change>(); |
| 875 |
for (RepositoryTaskAttribute newAttribute : newTaskData.getAttributes()) { |
880 |
for (RepositoryTaskAttribute newAttribute : newTaskData.getAttributes()) { |
|
|
881 |
List<String> newValues = newAttribute.getValues(); |
| 876 |
RepositoryTaskAttribute oldAttribute = oldTaskData.getAttribute(newAttribute.getId()); |
882 |
RepositoryTaskAttribute oldAttribute = oldTaskData.getAttribute(newAttribute.getId()); |
| 877 |
if (oldAttribute == null) { |
883 |
if (oldAttribute == null) { |
| 878 |
attributeChanged = true; |
884 |
changes.add(getDiff(newAttribute.getName(), null, newValues)); |
| 879 |
break; |
885 |
break; |
| 880 |
} |
886 |
} |
| 881 |
if (oldAttribute.getValue() != null && !oldAttribute.getValue().equals(newAttribute.getValue())) { |
887 |
List<String> oldValues = oldAttribute.getValues(); |
| 882 |
attributeChanged = true; |
888 |
if (!oldValues.equals(newValues)) { |
| 883 |
break; |
889 |
changes.add(getDiff(newAttribute.getName(), oldValues, newValues)); |
| 884 |
} else if (oldAttribute.getValues() != null && !oldAttribute.getValues().equals(newAttribute.getValues())) { |
|
|
| 885 |
attributeChanged = true; |
| 886 |
break; |
890 |
break; |
| 887 |
} |
891 |
} |
| 888 |
} |
892 |
} |
|
|
893 |
if (changes.isEmpty()) { |
| 894 |
return ""; |
| 895 |
} |
| 896 |
|
| 897 |
String details = ""; |
| 898 |
String sep = ""; |
| 899 |
for (Change c : changes) { |
| 900 |
details += sep; |
| 901 |
if (!c.removed.isEmpty()) { |
| 902 |
details += "- " + c.field + " " + c.removed; |
| 903 |
sep = "\n"; |
| 904 |
} |
| 905 |
if (!c.added.isEmpty()) { |
| 906 |
details += sep; |
| 907 |
details += "+ " + c.field + " " + c.added; |
| 908 |
sep = "\n"; |
| 909 |
} |
| 910 |
} |
| 911 |
return details; |
| 912 |
} |
| 889 |
|
913 |
|
| 890 |
if (attributeChanged) { |
914 |
private static Change getDiff(String field, List<String> oldValues, List<String> newValues) { |
| 891 |
if (descriptionText.equals("")) { |
915 |
Change c = new Change(field, newValues); |
| 892 |
descriptionText += "Attributes changed"; |
916 |
if(oldValues!=null) { |
|
|
917 |
for (String value : oldValues) { |
| 918 |
if(c.added.contains(value)) { |
| 919 |
c.added.remove(value); |
| 920 |
} else { |
| 921 |
c.removed.add(value); |
| 922 |
} |
| 893 |
} |
923 |
} |
| 894 |
} |
924 |
} |
| 895 |
return descriptionText; |
925 |
return c; |
| 896 |
} |
926 |
} |
| 897 |
|
927 |
|
|
|
928 |
static class Change { |
| 929 |
final String field; |
| 930 |
final List<String> added; |
| 931 |
final List<String> removed = new ArrayList<String>(); |
| 932 |
|
| 933 |
public Change(String field, List<String> newValues) { |
| 934 |
this.field = field; |
| 935 |
this.added = new ArrayList<String>(newValues); |
| 936 |
} |
| 937 |
|
| 938 |
} |
| 939 |
|
| 898 |
} |
940 |
} |