Changeset 5719 for ComponentRegistry


Ignore:
Timestamp:
10/15/14 15:22:05 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Nice titles for RSS feeds (needs to be tested), and groupId should be replaced or completed with the group name

Location:
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r5717 r5719  
    200200            return new ArrayList<ComponentDescription>();
    201201
    202        
    203        
     202
     203
    204204        } catch (ItemNotFoundException e) {
    205205            response.sendError(Status.NOT_FOUND.getStatusCode(), e.toString());
     
    241241            response.sendError(Status.FORBIDDEN.getStatusCode(), e.toString());
    242242            return new ArrayList<ProfileDescription>();
    243        
    244        
     243
     244
    245245        } catch (ItemNotFoundException e) {
    246246            response.sendError(Status.NOT_FOUND.getStatusCode(), e.toString());
     
    15381538    }
    15391539
     1540    private String helpToMakeTitleForRssDescriptions(String registrySpace, String groupId, String resource) {
     1541        if (registrySpace == null || (registrySpace.equalsIgnoreCase("group") && groupId == null)
     1542                || resource == null) {
     1543            return "Undefined registry space or uindefined type of resource";
     1544        }
     1545        if (registrySpace.equalsIgnoreCase("published")) {
     1546            return "Published " + resource;
     1547        }
     1548        if (registrySpace.equalsIgnoreCase("private")) {
     1549            return "Private " + resource;
     1550        }
     1551        if (registrySpace.equalsIgnoreCase("group") && groupId != null) {
     1552            return resource + " of group " + groupId;
     1553        }
     1554
     1555        return "Undefined registry space or uindefined type of resource";
     1556    }
     1557
    15401558    /**
    15411559     *
     
    15671585            response.sendError(Status.FORBIDDEN.getStatusCode(), e.toString());
    15681586            return new Rss();
    1569         }
    1570         catch (ItemNotFoundException e) {
     1587        } catch (ItemNotFoundException e) {
    15711588            response.sendError(Status.NOT_FOUND.getStatusCode(), e.toString());
    15721589            return new Rss();
    15731590        }
    15741591        // obsolete, add group Id
    1575         final RssCreatorDescriptions instance = new RssCreatorDescriptions(!registrySpace.equalsIgnoreCase("published"), getApplicationBaseURI(), "components",
     1592        String title = this.helpToMakeTitleForRssDescriptions(registrySpace, groupId, "Components");
     1593        final RssCreatorDescriptions instance = new RssCreatorDescriptions(getApplicationBaseURI(), "components",
    15761594                Integer.parseInt(limit), components,
    1577                 BaseDescription.COMPARE_ON_DATE);
     1595                BaseDescription.COMPARE_ON_DATE, title);
    15781596        final Rss rss = instance.getRss();
    15791597        LOG.debug("Releasing RSS of {} most recently registered components",
     
    16111629            response.sendError(Status.FORBIDDEN.getStatusCode(), e.toString());
    16121630            return new Rss();
    1613        
     1631
    16141632        } catch (ItemNotFoundException e) {
    16151633            response.sendError(Status.NOT_FOUND.getStatusCode(), e.toString());
    16161634            return new Rss();
    16171635        }
    1618         final RssCreatorDescriptions instance = new RssCreatorDescriptions(
    1619                 !registrySpace.equalsIgnoreCase("published"), getApplicationBaseURI(), "profiles",
     1636        String title = this.helpToMakeTitleForRssDescriptions(registrySpace, groupId, "Profiles");
     1637        final RssCreatorDescriptions instance = new RssCreatorDescriptions(getApplicationBaseURI(), "profiles",
    16201638                Integer.parseInt(limit), profiles,
    1621                 BaseDescription.COMPARE_ON_DATE);
     1639                BaseDescription.COMPARE_ON_DATE, title);
    16221640        final Rss rss = instance.getRss();
    16231641        LOG.debug("Releasing RSS of {} most recently registered profiles",
    16241642                limit);
    16251643        return rss;
     1644    }
     1645
     1646    private String helpToMakeTitleForRssComments(String itemId, String resource) {
     1647        if (itemId == null || resource == null) {
     1648            return "Undefined description";
     1649        }
     1650        return ("Comments for "+resource+ " "+itemId);
    16261651    }
    16271652
     
    16551680            final ProfileDescription pd = cr.getProfileDescriptionAccessControlled(profileId);
    16561681            final String profileName = pd.getName();
    1657             boolean profileIsPrivate = !pd.isPublic();
    1658             // obsolete, status must be involved, not boolean profileIsPrivate
    1659             final RssCreatorComments instance = new RssCreatorComments(profileIsPrivate,
     1682           
     1683            String title = this.helpToMakeTitleForRssComments(profileId, "profile");
     1684            final RssCreatorComments instance = new RssCreatorComments(
    16601685                    getApplicationBaseURI(), Integer.parseInt(limit), profileId,
    1661                     profileName, "profile", comments, Comment.COMPARE_ON_DATE);
     1686                    profileName, "profile", comments, Comment.COMPARE_ON_DATE, title);
    16621687            final Rss rss = instance.getRss();
    16631688            LOG.debug("Releasing RSS of {} most recent post on profile {}", limit,
     
    17041729            final ComponentDescription cd = cr.getComponentDescriptionAccessControlled(componentId);
    17051730            final String componentName = cd.getName();
    1706             final boolean isPrivate = !cd.isPublic();
    17071731            //oboslete. status must be involved, not boolean isPrivate
    1708             final RssCreatorComments instance = new RssCreatorComments(isPrivate,
     1732            String title = this.helpToMakeTitleForRssComments(componentId, "component");
     1733            final RssCreatorComments instance = new RssCreatorComments(
    17091734                    getApplicationBaseURI(), Integer.parseInt(limit), componentId,
    1710                     componentName, "component", comments, Comment.COMPARE_ON_DATE);
     1735                    componentName, "component", comments, Comment.COMPARE_ON_DATE, title);
    17111736            final Rss rss = instance.getRss();
    17121737            LOG.debug("Releasing RSS of {} most recent post on component {}",
     
    18891914        } catch (ItemNotFoundException e) {
    18901915            return Response.status(Status.NOT_FOUND).entity(e.getMessage()).build();
    1891        
     1916
    18921917        } catch (AuthenticationFailException e) {
    18931918            return Response.status(Status.UNAUTHORIZED).build();
    18941919        }
    18951920    }
    1896    
     1921
    18971922//    @Override
    18981923//    @DELETE
     
    19141939//        }
    19151940//    }
    1916 
    19171941    @Override
    19181942    @GET
     
    19922016            this.strings = strings;
    19932017        }
    1994        
    1995        
    19962018    }
    19972019}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rss/RssCreator.java

    r5549 r5719  
    2020    private String channelTitle;
    2121    private Comparator<T> comparator;
    22     protected final boolean isPrivate;
    2322    private List<T> objs;
    2423    private int limit;
    2524
    26     protected RssCreator(boolean isPrivate, String baseURI, int limit, List<T> objs) {
    27         this.isPrivate = isPrivate;
     25    protected RssCreator(String baseURI, int limit, List<T> objs) {
    2826        this.baseURI = baseURI;
    2927        this.limit = limit;
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rss/RssCreatorComments.java

    r5549 r5719  
    2727     * @param comparator compare comments by dates
    2828     */
    29     public RssCreatorComments(boolean isPrivate, String baseURI, int limit,
    30             String descriptionId, String descriptionName, String descriptionType, List<Comment> comms, Comparator<Comment> comparator) {
    31         super(isPrivate, baseURI, limit, comms);
    32         setChannelLink(baseURI + "?item=" + descriptionId + ((isPrivate) ? "&space=user" : "") + "&browserview=comments");
    33         setChannelTitle((isPrivate ? "Private " : "Public ") + descriptionType + " \"" + descriptionName + "\"");
     29    public RssCreatorComments(String baseURI, int limit,
     30            String descriptionId, String descriptionName, String descriptionType, List<Comment> comms, Comparator<Comment> comparator, String title) {
     31        super(baseURI, limit, comms);
     32        setChannelLink(baseURI + "?item=" + descriptionId + "&browserview=comments");
     33        setChannelTitle(title);
    3434        setChannelDescription(String.format("Comments feed for the %s \"%s\"", descriptionType, descriptionName));
    3535        setComparator(comparator);
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rss/RssCreatorDescriptions.java

    r5549 r5719  
    2323     * @param comparator compare descriptions by dates
    2424     */
    25     public RssCreatorDescriptions(boolean isPrivate, String baseURI, String descriptionType,
    26             int limit, List<T> descriptions, Comparator<T> comparator) {
    27         super(isPrivate, baseURI, limit, descriptions);
     25    public RssCreatorDescriptions(String baseURI, String descriptionType,
     26            int limit, List<T> descriptions, Comparator<T> comparator, String title) {
     27        super(baseURI, limit, descriptions);
    2828        setChannelLink(baseURI + "/");
    29         setChannelTitle((isPrivate ? "Private " : "Public ") + descriptionType);
     29        setChannelTitle(title);
    3030        setChannelDescription(String.format("News feed for the %s", descriptionType));
    3131        setComparator(comparator);
     
    4141    @Override
    4242    protected RssItem fromArgToRssItem(T desc) {
    43         String href = getBaseURI() + "?item=" + desc.getId() + (isPrivate ? "&space=user" : "");
     43        String href = getBaseURI() + "?item=" + desc.getId();
    4444        RssItem retval = new RssItem();
    4545        retval.setDescription(desc.getDescription());
Note: See TracChangeset for help on using the changeset viewer.