Changeset 2221
- Timestamp:
- 09/13/12 15:41:58 (12 years ago)
- Location:
- ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/RssCreator.java
r2218 r2221 55 55 * @param descrs 56 56 */ 57 /* public void setDescriptions(List<AbstractDescription> descrs){ 58 59 this.descrs = new ArrayList<AbstractDescription>(); 60 61 for (AbstractDescription currentdesc : descrs) 62 {this.descrs.add(currentdesc);}; 63 }/** 64 * 65 * @param descrs 66 */ 57 67 public void setComponentDescriptions(List<ComponentDescription> descrs){ 58 68 -
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/AbstractDescription.java
r1696 r2221 1 1 package clarin.cmdi.componentregistry.model; 2 2 3 import java.text.DateFormat; 3 4 import java.text.ParseException; 4 5 import java.util.Comparator; … … 166 167 return result; 167 168 } 169 168 170 public static final Comparator<? super AbstractDescription> COMPARE_ON_NAME = new Comparator<AbstractDescription>() { 169 171 … … 179 181 } 180 182 }; 183 184 public static final Comparator<? super AbstractDescription> COMPARE_ON_DATE = new Comparator<AbstractDescription>() { 185 186 //compare two components by the date of registration 187 // the dates, which are strings accrording to ISO 8601, compared lexicographically 188 189 public int compare(AbstractDescription o1, AbstractDescription o2) { 190 191 int result = 0; 192 193 DateFormat df = DateFormat.getDateTimeInstance(); 194 195 try{ 196 Date d1 = df.parse(o1.getRegistrationDate()); 197 Date d2 = df.parse(o2.getRegistrationDate()); 198 199 result = d1.compareTo(d2); 200 201 } catch (ParseException pe) {return 0;}; 202 203 204 205 return result; 206 } 207 }; 208 181 209 } -
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/ComponentDescription.java
r1371 r2221 10 10 11 11 @XmlRootElement(name = "componentDescription") 12 public class ComponentDescription extends AbstractDescription implements Serializable {12 public class ComponentDescription extends AbstractDescription implements Serializable { 13 13 14 14 private static final long serialVersionUID = 1L; 15 16 15 public static final Comparator<? super ComponentDescription> COMPARE_ON_GROUP_AND_NAME = new Comparator<ComponentDescription>() { 17 16 public int compare(ComponentDescription o1, ComponentDescription o2) { 18 17 int result = 0; 19 if (o1.getGroupName() != null && o2.getGroupName() != null) 18 if (o1.getGroupName() != null && o2.getGroupName() != null) { 20 19 result = o1.getGroupName().compareToIgnoreCase(o2.getGroupName()); 20 } 21 21 if (result == 0) { 22 22 if (o1.getName() != null && o2.getName() != null) { … … 29 29 } 30 30 }; 31 31 32 32 33 public static ComponentDescription createNewDescription() { … … 37 38 return desc; 38 39 } 39 40 40 } -
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r2218 r2221 29 29 import java.util.ArrayList; 30 30 import java.util.Arrays; 31 import java.util.Co mparator;31 import java.util.Collections; 32 32 import java.util.List; 33 33 import javax.servlet.http.HttpServletRequest; … … 965 965 } 966 966 967 /* 968 * generating rss: commom part for profile and component descriptions 969 * 970 */ 971 972 /* private Rss getRss(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @QueryParam(NUMBER_OF_RSSITEMS) @DefaultValue("20") String limit, 973 List<AbstractDescription> descs) throws ComponentRegistryException { 974 975 976 977 RssCreator rssCreator = new RssCreator(); 978 int limitInt = Integer.parseInt(limit); 979 980 if (descs.size()<limitInt) {limitInt = descs.size();}; 981 982 List<AbstractDescription> sublist = descs.subList(0, limitInt); 983 984 Collections.sort(sublist, AbstractDescription.COMPARE_ON_DATE); 985 986 rssCreator.setComponentDescriptions(sublist); 987 988 if (userspace) {rssCreator.setTitle("Workspace components");} 989 else {rssCreator.setTitle("Public components");} 990 991 992 Rss rss =rssCreator.makeRssChannel(); 993 994 LOG.info("Releasing " + limitInt + "most recent registered components into the world sorted by their registration date-and-time"); 995 return rss; 996 }*/ 967 997 //////////////////////////////////////////////// 968 998 @GET 969 999 @Path("/components/rss") 970 1000 @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 971 public Rss getRss (@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @QueryParam(NUMBER_OF_RSSITEMS) @DefaultValue("20") String limit) throws ComponentRegistryException {1001 public Rss getRssComponent(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @QueryParam(NUMBER_OF_RSSITEMS) @DefaultValue("20") String limit) throws ComponentRegistryException { 972 1002 973 long start = System.currentTimeMillis();1003 974 1004 List<ComponentDescription> components = getRegistry(getStatus(userspace)).getComponentDescriptions(); 975 1005 … … 982 1012 983 1013 List<ComponentDescription> sublist = components.subList(0, limitInt); 984 //Collections.sort(sublist, ); 1014 1015 Collections.sort(sublist, ComponentDescription.COMPARE_ON_DATE); 985 1016 986 1017 rssCreator.setComponentDescriptions(sublist); … … 992 1023 Rss rss =rssCreator.makeRssChannel(); 993 1024 994 LOG.info("Releasing " + limitInt + "most recent registered components into the world sorted by creations day");1025 LOG.info("Releasing " + limitInt + "most recent registered components into the world sorted by their registration date-and-time"); 995 1026 return rss; 996 1027 } 997 1028 1029 //////////////////////////////////////////////// 1030 @GET 1031 @Path("/profiles/rss") 1032 @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 1033 public Rss getRssProfile(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @QueryParam(NUMBER_OF_RSSITEMS) @DefaultValue("20") String limit) throws ComponentRegistryException { 1034 1035 long start = System.currentTimeMillis(); 1036 List<ProfileDescription> profiles = getRegistry(getStatus(userspace)).getProfileDescriptions(); 1037 1038 1039 1040 RssCreator rssCreator = new RssCreator(); 1041 int limitInt = Integer.parseInt(limit); 1042 1043 if (profiles.size()<limitInt) {limitInt = profiles.size();}; 1044 1045 List<ProfileDescription> sublist = profiles.subList(0, limitInt); 998 1046 999 1000 /* public static final Comparator<? super ComponentDescription> COMPARE_ON_GROUP_AND_NAME = new Comparator<ComponentDescription>() { 1001 public int compare(ComponentDescription o1, ComponentDescription o2) { 1002 int result = 0; 1003 if (o1.getGroupName() != null && o2.getGroupName() != null) 1004 result = o1.getGroupName().compareToIgnoreCase(o2.getGroupName()); 1005 if (result == 0) { 1006 if (o1.getName() != null && o2.getName() != null) { 1007 result = o1.getName().compareToIgnoreCase(o2.getName()); 1008 } else { 1009 result = o1.getId().compareTo(o2.getId()); 1010 } 1011 } 1012 return result; 1013 } 1014 };*/ 1047 Collections.sort(sublist, ProfileDescription.COMPARE_ON_DATE); 1048 1049 rssCreator.setProfileDescriptions(sublist); 1050 1051 if (userspace) {rssCreator.setTitle("Workspace profiles");} 1052 else {rssCreator.setTitle("Public profiles");} 1053 1054 1055 Rss rss =rssCreator.makeRssChannel(); 1056 1057 LOG.info("Releasing " + limitInt + "most recent registered profiles into the world sorted by their registration date-and-time"); 1058 return rss; 1059 } 1060 1015 1061 }
Note: See TracChangeset
for help on using the changeset viewer.