001/*
002 *  Copyright 2014 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.sms.dao;
017
018import javax.jcr.Node;
019import javax.jcr.PathNotFoundException;
020import javax.jcr.RepositoryException;
021
022import org.ametys.plugins.repository.AmetysObject;
023import org.ametys.plugins.repository.AmetysRepositoryException;
024import org.ametys.plugins.repository.RepositoryConstants;
025import org.ametys.plugins.repository.jcr.DefaultTraversableAmetysObject;
026
027/**
028 * The JCR object : a sms list
029 */
030public class JCRSubscribersList extends DefaultTraversableAmetysObject<SubscribersListFactory>
031{
032    /** Constants for title metadata. */
033    private static final String __METADATA_TITLE = RepositoryConstants.NAMESPACE_PREFIX_INTERNAL + ":title";
034    /** Constants for description metadata. */
035    private static final String __METADATA_DESC = RepositoryConstants.NAMESPACE_PREFIX_INTERNAL + ":description";
036
037    /**
038    * constructor
039    * @param node the node backing this {@link AmetysObject}.
040    * @param parentPath the parent path in the Ametys hierarchy.
041    * @param factory the {@link SubscribersListFactory} which creates the AmetysObject.
042    */
043    public JCRSubscribersList (Node node, String parentPath, SubscribersListFactory factory)
044    {
045           super(node, parentPath, factory);
046    }
047    
048    /**
049     * Retrieves the title.
050     * @return the title.
051     * @throws AmetysRepositoryException if an error occurs.
052     */
053    public String getTitle() throws AmetysRepositoryException
054    {
055        try
056        {
057            return getNode().getProperty(__METADATA_TITLE).getString();
058        }
059        catch (PathNotFoundException e)
060        {
061            return null;
062        }
063        catch (RepositoryException e)
064        {
065            throw new AmetysRepositoryException("Unable to get title property", e);
066        }
067    }
068    
069    /**
070     * Set the title.
071     * @param title the title.
072     * @throws AmetysRepositoryException if an error occurs.
073     */
074    public void setTitle(String title) throws AmetysRepositoryException
075    {
076        try
077        {
078            getNode().setProperty(__METADATA_TITLE, title);
079        }
080        catch (RepositoryException e)
081        {
082            throw new AmetysRepositoryException("Unable to set title property", e);
083        }
084    }
085    
086    /**
087     * Retrieves the description.
088     * @return the description.
089     * @throws AmetysRepositoryException if an error occurs.
090     */
091    public String getDescription() throws AmetysRepositoryException
092    {
093        try
094        {
095            return getNode().getProperty(__METADATA_DESC).getString();
096        }
097        catch (PathNotFoundException e)
098        {
099            return null;
100        }
101        catch (RepositoryException e)
102        {
103            throw new AmetysRepositoryException("Unable to get description property", e);
104        }
105    }
106    
107    /**
108     * Set the description.
109     * @param description the description.
110     * @throws AmetysRepositoryException if an error occurs.
111     */
112    public void setDescription(String description) throws AmetysRepositoryException
113    {
114        try
115        {
116            getNode().setProperty(__METADATA_DESC, description);
117        }
118        catch (RepositoryException e)
119        {
120            throw new AmetysRepositoryException("Unable to set description property", e);
121        }
122    }
123}