Changeset 1631


Ignore:
Timestamp:
11/28/11 15:46:02 (12 years ago)
Author:
jeafer
Message:

Jean-Charles branch initial commit,
Changes regarding comment on the ComponentRegistry service.
Get comment from RestService? to Database access (CommentsDao?) implemented.
TestComment? class in development

Location:
ComponentRegistry/branches/jeaferversion
Files:
5 added
25 edited
1 copied

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/pom.xml

    r1573 r1631  
    2828        </profile>
    2929    </profiles>
    30 
     30   
    3131    <dependencies>
    3232        <dependency>
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/Browse.mxml

    r1092 r1631  
    1313        <mx:Script>
    1414                <![CDATA[
     15                        import clarin.cmdi.componentregistry.browser.BrowserSelectionEvent;
     16                        import clarin.cmdi.componentregistry.common.CommentDescription;
     17                        import clarin.cmdi.componentregistry.common.ItemDescription;
     18                        import clarin.cmdi.componentregistry.common.Profile;
     19                        import clarin.cmdi.componentregistry.common.components.BrowseContextMenu;
     20                        import clarin.cmdi.componentregistry.common.components.RegistryViewStack;
    1521                        import clarin.cmdi.componentregistry.services.BrowserService;
     22                        import clarin.cmdi.componentregistry.services.ComponentInfoService;
     23                        import clarin.cmdi.componentregistry.services.ComponentListService;
    1624                        import clarin.cmdi.componentregistry.services.Config;
    17                         import clarin.cmdi.componentregistry.services.ComponentInfoService;
     25                        import clarin.cmdi.componentregistry.services.DeleteService;
    1826                        import clarin.cmdi.componentregistry.services.ProfileInfoService;
    1927                        import clarin.cmdi.componentregistry.services.ProfileListService;
     28                        import clarin.cmdi.componentregistry.services.CommentInfoService;
     29                        import clarin.cmdi.componentregistry.services.CommentListService;
     30                       
     31                        import mx.collections.ArrayCollection;
     32                        import mx.controls.Alert;
    2033                        import mx.events.CollectionEvent;
    21                         import mx.collections.ArrayCollection;
    22                         import clarin.cmdi.componentregistry.common.components.RegistryViewStack;
    23                         import clarin.cmdi.componentregistry.common.components.BrowseContextMenu;
    24                         import clarin.cmdi.componentregistry.services.DeleteService;
    25                         import clarin.cmdi.componentregistry.services.ComponentListService;
    26                         import clarin.cmdi.componentregistry.common.ItemDescription;
    27                         import mx.controls.Alert;
    28                         import clarin.cmdi.componentregistry.browser.BrowserSelectionEvent;
    29                         import clarin.cmdi.componentregistry.common.Profile;
    3034
    3135                        public static const START_ITEM_LOADED:String = "startItemLoaded";
     
    3842                        private var profilesSrv:ProfileListService = ProfileListService.getInstance(Config.instance.userSpace);
    3943                        [Bindable]
     44                        private var commentsSrv:CommentListService = CommentListService.getInstance(Config.instance.userSpace);
     45                        [Bindable]
    4046                        private var profileSrv:ProfileInfoService = new ProfileInfoService();
    4147                        [Bindable]
    4248                        private var componentSrv:ComponentInfoService = new ComponentInfoService();
     49                        [Bindable]
     50                        private var commentSrv:CommentInfoService = new CommentInfoService();
    4351
    4452                        private var deleteSrv:DeleteService = DeleteService.instance;
     
    5260                        [Bindable]
    5361                        private var selectedComponentItem:ItemDescription;
     62                        [Bindable]
     63                        private var selectedCommentItem:CommentDescription;
    5464                        private var startupItemId:String = null;
    5565
     
    6575                        }
    6676
    67                         private function toggleUserSpace(event:Event):void {
     77                        private function toggleUserSpace(event:Event):void {
    6878                                var userSpace:Boolean = Config.instance.userSpace;
    6979                                componentsSrv = ComponentListService.getInstance(userSpace);
    7080                                profilesSrv = ProfileListService.getInstance(userSpace);
    7181                                refresh();
    72                         }
    73 
    74                         private function creationComplete():void {
     82                        } 
     83
     84                        private function creationComplete():void {
    7585                                refresh();
    7686                        }
     
    8191                                        componentsSrv.addEventListener(BrowserService.ITEMS_LOADED, componentsLoaded);
    8292                                        profilesSrv.addEventListener(BrowserService.ITEMS_LOADED, profilesLoaded);
    83                                 }
    84                                 refresh();
    85             }
    86 
    87                         public function refresh():void {
     93                                        //commentsSrv.addEventListener(BrowserService.ITEMS_LOADED, commentsLoaded);
     94                                }
     95                                refresh();
     96            }
     97
     98                        public function refresh():void {
    8899                                componentsSrv.load();
    89100                                profilesSrv.load();
    90                         }
     101                        } 
    91102
    92103                        private function profilesLoaded(event:Event):void {
     
    101112                                componentsSrv.removeEventListener(BrowserService.ITEMS_LOADED, componentsLoaded);
    102113                        }
     114                       
     115/*                      private function commentsLoaded(event:Event):void {
     116                                var item:CommentDescription = CommentListService.findDescription(startupItemId);
     117                                loadStartupComment(item);
     118                                commentsSrv.removeEventListener(BrowserService.ITEMS_LOADED, commentsLoaded);
     119                        } */
    103120                       
    104121                        private function loadStartupItem(item:ItemDescription):void {
     
    112129                                startupItemLoaded = true;
    113130                        }
     131                       
     132/*                      private function loadStartupComment(item:CommentDescription):void {
     133                                if (item) {
     134                                        setSelectedCommentDescription(item);
     135                                        startupItemId = null;
     136                                        dispatchEvent(new Event(START_ITEM_LOADED));
     137                                } else if (startupItemLoaded) {
     138                                        dispatchEvent(new Event(START_ITEM_LOADED));
     139                                }
     140                                startupItemLoaded = true;
     141                        } */
    114142
    115143                        private function loadProfileInfoPage(event:BrowserSelectionEvent):void {
     
    132160                                }
    133161                        }
     162                       
     163/*                      public function setSelectedCommentDescription(desc:CommentDescription):void {
     164                                        tabnav.selectedIndex = 0;
     165                                        this.selectedCommentItem = desc;
     166                                        commentSrv.load(desc);
     167                        } */
    134168
    135169                        public function getSelectedStartItem():ItemDescription {
     
    170204                                <browser:BrowserOverviewList id="profilesOverview"
    171205                                                                                         browserColumns="{browserColumns.getProfileColumns()}"
    172                                                                                          browserDataProvider="{profilesSrv.itemDescriptions}"
     206                                                                                         browserDataProvider="{profilesSrv.itemDescriptions}"                                                                                   
    173207                                                                                         browserItemSelected="{loadProfileInfoPage(event)}"
    174208                                                                                         itemToScrollTo="{selectedProfileItem}"
     
    198232                                                                                   height="50%"
    199233                                                                                   contextMenu="{componentsMenu.cm}"/>
    200 
    201234                        </mx:VDividedBox>
    202235                </mx:TabNavigator>
     236
    203237        </mx:VBox>
    204238</mx:Canvas>
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/BrowserColumns.as

    r1228 r1631  
    3131                }
    3232
     33               
    3334                private function createColumn(dataField:String, headerText:String):DataGridColumn {
    3435                        var c:DataGridColumn = new DataGridColumn();
     
    6162                        return sort
    6263                }
     64               
     65                public static function getInitialSortForComments():Sort {
     66                        var sort:Sort = new Sort();
     67                        var sortByGroup:SortField = new SortField("creatorName", true);
     68                        var sortByName:SortField = new SortField("id", true);
     69                        var sortByDate:SortField = new SortField("registrationDate", true, true);
     70                        sortByDate.compareFunction = compareRegistrationDate;
     71                        sort.fields = [sortByGroup, sortByName, sortByDate];
     72                        return sort
     73                }
    6374
    6475                private function createDateColumn():DataGridColumn {
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/BrowserSelectionEvent.as

    r117 r1631  
    11package clarin.cmdi.componentregistry.browser {
     2        import clarin.cmdi.componentregistry.common.CommentDescription;
    23        import clarin.cmdi.componentregistry.common.ItemDescription;
    3 
     4       
    45        import flash.events.Event;
    56
     
    89                public static const BROWSER_ITEM_SELECTED:String = "browserItemSelected";
    910                private var _itemDescription:ItemDescription;
    10 
     11                private var _commentDescription:CommentDescription;
    1112                public function BrowserSelectionEvent(itemDescription:ItemDescription, bubbles:Boolean = false, cancelable:Boolean = false) {
    1213                        super(BROWSER_ITEM_SELECTED, bubbles, cancelable);
     
    1617                public function get itemDescription():ItemDescription {
    1718                        return _itemDescription;
     19                }
     20               
     21                public function get commentDescription():CommentDescription {
     22                        return _commentDescription;
    1823                }
    1924
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/ComponentInfoPage.mxml

    r249 r1631  
    66                 backgroundColor="#DDE3EF"
    77                 >
    8 
     8       
    99        <common:Component id="component"/>
    10 
    1110        <browser:infoPage id="infoPanel"
    1211                                   cmdComponent="{component.componentMD.xml}"
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/infoPage.mxml

    r249 r1631  
    44                 xmlns:common="clarin.cmdi.componentregistry.common.*"
    55                 xmlns:browser="clarin.cmdi.componentregistry.browser.*">
     6       
     7        <mx:Metadata>
     8                [Event(name="startItemLoaded",type="flash.events.Event")]
     9        </mx:Metadata>
     10        <mx:Array id="browserColumns"/>
     11       
     12        <mx:Script>
     13                import clarin.cmdi.componentregistry.services.CommentInfoService;
     14                import clarin.cmdi.componentregistry.services.CommentListService;
     15                import clarin.cmdi.componentregistry.services.Config;
     16                import clarin.cmdi.componentregistry.common.components.BrowseContextMenu;
     17                import clarin.cmdi.componentregistry.common.components.RegistryViewStack;
     18                import clarin.cmdi.componentregistry.services.DeleteService;
     19                import clarin.cmdi.componentregistry.services.BrowserService;
     20               
     21                [Bindable]
     22                private var commentsMenu:BrowseContextMenu;
     23                [Bindable]
     24                private var selectedCommentItem:CommentDescription;
     25                [Bindable]
     26                private var commentsSrv:CommentListService = CommentListService.getInstance(Config.instance.userSpace);
     27                [Bindable]
     28                private var commentSrv:CommentInfoService = new CommentInfoService();
     29               
     30                public static const START_ITEM_LOADED:String = "startItemLoaded";
     31                private var startupItemLoaded:Boolean = false;
     32                private var deleteSrv:DeleteService = DeleteService.instance;
     33                private var _itemToScrollToComment:CommentDescription;         
     34                private var startupItemId:String = null;
     35               
     36                public function init():void {
     37                        commentsMenu = new BrowseContextMenu(true);
     38                        commentsMenu.viewStack = this.parent as RegistryViewStack;
     39                        commentsMenu.deleteService = deleteSrv;
     40                        deleteSrv.addEventListener(DeleteService.ITEM_DELETED, handleItemDeleted);
     41                }
     42               
     43                public function loadStartup():void {
     44                        startupItemId = Config.instance.startupItem;
     45                        if (startupItemId) { //only load this once on startup
     46                                commentsSrv.addEventListener(BrowserService.ITEMS_LOADED, commentsLoaded);
     47                        }
     48                       
     49                        private function commentsLoaded(event:Event):void {
     50                                var item:CommentDescription = CommentListService.findDescription(startupItemId);
     51                                loadStartupComment(item);
     52                                commentsSrv.removeEventListener(BrowserService.ITEMS_LOADED, commentsLoaded);
     53                        }
     54                       
     55                        private function loadStartupComment(item:CommentDescription):void {
     56                                if (item) {
     57                                        setSelectedCommentDescription(item);
     58                                        startupItemId = null;
     59                                        dispatchEvent(new Event(START_ITEM_LOADED));
     60                                } else if (startupItemLoaded) {
     61                                        dispatchEvent(new Event(START_ITEM_LOADED));
     62                                }
     63                                startupItemLoaded = true;
     64                        }
     65                       
     66                        public function setSelectedCommentDescription(desc:CommentDescription):void {
     67                                tabnav.selectedIndex = 0;
     68                                this.selectedCommentItem = desc;
     69                                commentSrv.load(desc);
     70                        }
     71                       
     72                public function refresh():void {
     73                        commentsSrv.load();
     74                }
    675
     76               
     77                private function handleItemDeleted(event:Event):void {
     78                        refresh();
     79                }
     80               
     81                private function loadCommentInfoPage(event:BrowserSelectionEvent):void {
     82                        commentSrv.load(event.commentDescription);
     83                       
     84                       
     85                }
     86               
     87        </mx:Script>
     88       
    789        <mx:XML id="cmdComponent"/>
     90        <mx:XML id="cmdComment"/>
     91        <mx:XML id="nrOfComments"/>
    892        <common:ItemDescription id="itemDescription"/>
     93        <common:CommentDescription id="commentDescription"/>
     94       
    995        <mx:String id="headerLabel"/>
    10 
     96       
    1197        <mx:HBox horizontalAlign="center"
    1298                         verticalAlign="middle"
     
    19105                                                        dataProvider="{infoViewStack}"/>
    20106        </mx:HBox>
    21 
     107       
     108       
    22109        <mx:ViewStack id="infoViewStack"
    23110                                  height="100%"
    24111                                  width="100%"
    25112                                  styleName="borderStyles">
    26 
     113               
    27114                <browser:xmlBrowsePanel id="viewPanel"
    28115                                                                label="view"
     
    32119                                                  label="xml"
    33120                                                  cmdComponent="{cmdComponent}"/>
    34 
     121               
     122                <mx:VDividedBox label="Comments({nrOfComments})"
     123                                                width="100%">
     124                        <browser:xmlCommentPanel 
     125                                id="viewAllComments" width="399" height="109"
     126                                browseMenu="{commentsMenu}"
     127                                browserColumns="{browserColumns.getCommentColumns()}"
     128                                browserCommentSelected="{loadCommentInfoPage(event)}"
     129                                browserDataProvider="{commentsSrv.itemDescriptions}"
     130                                itemToScrollToComment="{selectedCommentItem}"
     131                                cmdComment="{cmdComment}"
     132                                commentDescription="{commentDescription}"
     133                                />
     134                        <!-- id="viewComments" width="100%" -->
     135                </mx:VDividedBox>
    35136        </mx:ViewStack>
    36 
     137       
    37138</mx:VBox>
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/xmlPanel.mxml

    r117 r1631  
    11<?xml version="1.0" encoding="utf-8"?>
    22<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
    3                  xmlns:comp="clarin.cmdi.componentregistry.common.components.*">
     3                 xmlns:comp="clarin.cmdi.componentregistry.common.components.*" xmlns:common="clarin.cmdi.componentregistry.common.*">
    44
    55        <mx:XML id="cmdComponent"/>
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/ItemDescription.as

    r429 r1631  
    7070                        create(itemDescription, Config.instance.componentInfoUrl, false, isInUserSpace);
    7171                }
    72 
    7372        }
    7473}
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/editor/model/CMDModelFactory.as

    r1578 r1631  
    11package clarin.cmdi.componentregistry.editor.model {
    22        import clarin.cmdi.componentregistry.common.ComponentMD;
     3        import clarin.cmdi.componentregistry.common.CommentMD;
    34        import clarin.cmdi.componentregistry.common.ItemDescription;
     5        import clarin.cmdi.componentregistry.common.CommentDescription;
    46        import clarin.cmdi.componentregistry.editor.ValueSchemeItem;
    5 
     7       
    68        import mx.collections.ArrayCollection;
    79        import mx.collections.XMLListCollection;
     
    2224                                var cmdComp:CMDComponent = createComponent(component);
    2325                                result.cmdComponents.addItem(cmdComp);
     26                        }
     27                        return result;
     28                }
     29               
     30                public static function createCommentModel(xml:XML, description:CommentDescription):CMDSpec {
     31                        var result:CMDSpec = new CMDSpec(xml.@isProfile == "true");
     32                        result.headerName = xml.Header.Name;
     33                        result.headerId = xml.Header.ID;
     34                        result.headerDescription = xml.Header.Description;
     35                        var comments:XMLList = xml.elements(CommentMD.CMD_COMMENT);
     36                        for each (var comment:XML in comments) {
     37                                var cmdComp:CMDComment = createComment(comment);
     38                                result.cmdComponents.addItem(cmdComp);
     39                        }
     40                        return result;
     41                }
     42               
     43                private static function createComment(xml:XML):CMDComment {
     44                        var result:CMDComment = new CMDComment();
     45                        result.componentId = xml.@ComponentId;
     46                        result.profileId = xml.@ProfileId;
     47                        result.creatorName = xml.@creatorName;
     48                        result.filename = xml.@filename;
     49                        result.registerDate= xml.@registerDate;
     50                        result.commentId= xml.@commentId;
     51                        var comments:XMLList = xml.comments();
     52                        for each (var comment:XML in comments) {
     53                                var cmdComment:CMDComment = createComment(comment);
     54                                result.cmdComments.addItem(cmdComment);
    2455                        }
    2556                        return result;
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/BrowserService.as

    r1375 r1631  
    11package clarin.cmdi.componentregistry.services {
    22        import clarin.cmdi.componentregistry.common.ItemDescription;
     3        import clarin.cmdi.componentregistry.common.CommentDescription;
    34       
    45        import com.adobe.net.URI;
     
    9293                        return null;
    9394                }
     95               
     96                public function lookUpComDescription(componentId:String):CommentDescription {
     97                        for each (var item:CommentDescription in unFilteredItemDescriptions) {
     98                                if (item.id == componentId) {
     99                                        return item;
     100                                }
     101                        }
     102                        return null;
     103                }
    94104        }
    95105}
  • ComponentRegistry/branches/jeaferversion/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/Config.as

    r1473 r1631  
    2828                private static const COMPONENT_LIST_URL:String = "/rest/registry/components";
    2929                private static const PROFILE_LIST_URL:String = "/rest/registry/profiles";
     30                private static const COMMENT_LIST_URL:String = "/rest/registry/comments";
     31/*              private static const COMMENTPROFILE_LIST_URL:String = "/rest/registry/profiles/comments";
     32                private static const COMMENTCOMPONENT_LIST_URL:String = "/rest/registry/components/comments";*/
    3033                private static const COMPONENT_USAGE_URL:String = "/rest/registry/components/usage/";
    3134                private static const UPLOAD_PROFILE_SERVICE_URL:String = "/rest/registry/profiles";
    3235                private static const UPLOAD_COMPONENT_SERVICE_URL:String = "/rest/registry/components";
     36/*              private static const UPLOAD_COMMENTC_SERVICE_URL:String = "/rest/registry/components/comments";
     37                private static const UPLOAD_COMMENTP_SERVICE_URL:String = "/rest/registry/profiles/comments";*/
    3338                private static const PROFILE_INFO_URL:String = "/rest/registry/profiles/";
    3439                private static const COMPONENT_INFO_URL:String = "/rest/registry/components/";
     40                private static const COMMENTPROFILE_INFO_URL:String = "/rest/registry/profiles/comments";
     41                private static const COMMENTCOMPONENT_INFO_URL:String = "/rest/registry/components/comments";
    3542                private static const PING_SESSION_URL:String = "/rest/registry/pingSession";
    3643                private static const ISOCAT_SERVLET:String = "/isocat";
     
    9097                }
    9198               
     99                public function get commentListUrl():String {
     100                        return _serviceRootUrl + COMMENT_LIST_URL;
     101                }
     102               
     103/*              public function get commentProfileListUrl():String {
     104                        return _serviceRootUrl + COMMENTPROFILE_LIST_URL;
     105                }
     106               
     107                public function get commentComponentListUrl():String {
     108                        return _serviceRootUrl + COMMENTCOMPONENT_LIST_URL;
     109                }*/
     110               
    92111                public function get componentUsageUrl():String {
    93112                        return _serviceRootUrl + COMPONENT_USAGE_URL;
     
    101120                        return _serviceRootUrl + COMPONENT_INFO_URL;
    102121                }
     122               
     123                public function get commentProfileInfoUrl():String {
     124                        return _serviceRootUrl + COMMENTPROFILE_INFO_URL;
     125                }
     126                public function get commentComponentInfoUrl():String {
     127                        return _serviceRootUrl + COMMENTCOMPONENT_INFO_URL;
     128                }
    103129
    104130                public function get uploadProfileUrl():String {
     
    109135                        return _serviceRootUrl + UPLOAD_COMPONENT_SERVICE_URL;
    110136                }
     137               
     138/*              public function get uploadCommentPURL():String {
     139                        return _serviceRootUrl + UPLOAD_COMMENTP_SERVICE_URL;
     140                }
     141               
     142                public function get uploadCommentCURL():String {
     143                        return _serviceRootUrl + UPLOAD_COMMENTC_SERVICE_URL;
     144                }*/
    111145
    112146                public function get isocatSearchUrl():String {
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry

    • Property svn:ignore
      •  

        old new  
        77profiles.xml
        88nb-configuration.xml
         9nbactions-Run without tests.xml
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/pom.xml

    r1592 r1631  
    197197        <ComponentRegistrySwfName>${pom.artifactId}-${ComponentBrowserGui.version}</ComponentRegistrySwfName>
    198198        <flexDebug>0</flexDebug>
     199        <netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>
    199200    </properties>
    200201
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/CMDComponentSpecExpander.java

    r1562 r1631  
    103103        return result;
    104104    }
     105   
     106//    protected CMDComponentSpec expandComment(String commentId) throws ComponentRegistryException {
     107//        CMDComponentSpec result = getUncachedComment(commentId);
     108//        List<CMDComponentType> cmdComponents = result.getCMDComponent();
     109//        expandNestedComponent(cmdComponents);
     110//        return result;
     111//    }
    105112
    106113    /**
     
    111118
    112119    protected abstract CMDComponentSpec getUncachedProfile(String profileId) throws ComponentRegistryException;
     120   
     121//    protected abstract CMDComponentSpec getUncachedComment(String commentId) throws ComponentRegistryException;
    113122}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java

    r1604 r1631  
    88import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    99import clarin.cmdi.componentregistry.model.AbstractDescription;
     10import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
    1011import clarin.cmdi.componentregistry.model.ComponentDescription;
    1112import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    3233    List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException;
    3334
     35   
     36    //List<Comment> getComments() throws ComponentRegistryException;
     37   
    3438    /**
    3539     *
     
    4448
    4549    CMDComponentSpec getMDComponent(String id) throws ComponentRegistryException;
     50    //CMDComponentSpec getMDComment(String id) throws ComponentRegistryException;
    4651
    4752    /**
     
    98103            DeleteFailedException;
    99104
     105   
     106    //void deleteMDComment(String commentId, Principal principal)throws IOException, UserUnauthorizedException, ComponentRegistryException, DeleteFailedException;
    100107    /**
    101108     *
     
    136143     */
    137144    List<ComponentDescription> getDeletedComponentDescriptions();
     145   
     146   
     147    List<Comment> getCommentsInProfile(String profileId) throws ComponentRegistryException;
     148   
     149   
     150   
     151    Comment getSpecifiedCommentInProfile(String commentId) throws ComponentRegistryException;
     152   
     153    List<Comment> getCommentsInComponent(String componentId) throws ComponentRegistryException;
     154    Comment getSpecifiedCommentInComponent(String commentId) throws ComponentRegistryException;
     155
     156
    138157
    139158
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java

    r1604 r1631  
    2020import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header;
    2121import clarin.cmdi.componentregistry.model.AbstractDescription;
     22import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
    2223import clarin.cmdi.componentregistry.model.ComponentDescription;
    2324import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    3334    @Override
    3435    public List<ComponentDescription> getUsageInComponents(String componentId) throws ComponentRegistryException {
    35         List<ComponentDescription> result = new ArrayList<ComponentDescription>();
    36         List<ComponentDescription> descs = getComponentDescriptions();
    37         for (ComponentDescription desc : descs) {
    38             CMDComponentSpec spec = getMDComponent(desc.getId());
    39             if (spec != null && findComponentId(componentId, spec.getCMDComponent())) {
    40                 result.add(desc);
    41             }
    42         }
    43         return result;
     36        List<ComponentDescription> result = new ArrayList<ComponentDescription>();
     37        List<ComponentDescription> descs = getComponentDescriptions();
     38        for (ComponentDescription desc : descs) {
     39            CMDComponentSpec spec = getMDComponent(desc.getId());
     40            if (spec != null && findComponentId(componentId, spec.getCMDComponent())) {
     41                result.add(desc);
     42            }
     43        }
     44        return result;
    4445    }
    4546
    4647    @Override
    4748    public List<ProfileDescription> getUsageInProfiles(String componentId) throws ComponentRegistryException {
    48         List<ProfileDescription> result = new ArrayList<ProfileDescription>();
    49         for (ProfileDescription profileDescription : getProfileDescriptions()) {
    50             CMDComponentSpec profile = getMDProfile(profileDescription.getId());
    51             if (profile != null && findComponentId(componentId, profile.getCMDComponent())) {
    52                 result.add(profileDescription);
    53             }
    54         }
    55         return result;
     49        List<ProfileDescription> result = new ArrayList<ProfileDescription>();
     50        for (ProfileDescription profileDescription : getProfileDescriptions()) {
     51            CMDComponentSpec profile = getMDProfile(profileDescription.getId());
     52            if (profile != null && findComponentId(componentId, profile.getCMDComponent())) {
     53                result.add(profileDescription);
     54            }
     55        }
     56        return result;
    5657    }
     58
     59//    public List<Comment> getUsageInComments(String componentId) throws ComponentRegistryException {
     60//        List<Comment> result = new ArrayList<Comment>();
     61//        for (Comment comment : getComments()) {
     62//            CMDComponentSpec myComment = getMDComment(comment.getId());
     63//            if (myComment != null && findComponentId(componentId, myComment.getCMDComponent())) {
     64//            result.add(comment);
     65//            System.out.println("get unsage in comments : " + myComment + "\n");
     66//            }
     67//        }
     68//       
     69//        return result;
     70//    }
    5771
    5872    /**
     
    6377    @Override
    6478    public List<ProfileDescription> getProfileDescriptionsForMetadaEditor() throws ComponentRegistryException {
    65         // TODO: Below can also be done by accepting and passing a parameter in the ProfileDescriptionDao, should have better performance
     79        // TODO: Below can also be done by accepting and passing a parameter in the ProfileDescriptionDao, should have better performance
    6680
    67         // Get all profile descriptions
    68         List<ProfileDescription> descriptionsCollection = getProfileDescriptions();
    69         // Filter out ones that do should not be shown for metadata editor
    70         ArrayList<ProfileDescription> descriptions = new ArrayList<ProfileDescription>(descriptionsCollection.size());
    71         for (ProfileDescription profile : descriptionsCollection) {
    72             if (((ProfileDescription) profile).isShowInEditor()) {
    73                 descriptions.add((ProfileDescription) profile);
    74             }
    75         }
    76         // Return filtered list
    77         return descriptions;
     81        // Get all profile descriptions
     82        List<ProfileDescription> descriptionsCollection = getProfileDescriptions();
     83        // Filter out ones that do should not be shown for metadata editor
     84        ArrayList<ProfileDescription> descriptions = new ArrayList<ProfileDescription>(descriptionsCollection.size());
     85        for (ProfileDescription profile : descriptionsCollection) {
     86            if (((ProfileDescription) profile).isShowInEditor()) {
     87                descriptions.add((ProfileDescription) profile);
     88            }
     89        }
     90        // Return filtered list
     91        return descriptions;
    7892    }
    7993
    8094    /* HELPER METHODS */
    8195    protected static String stripRegistryId(String id) {
    82         return StringUtils.removeStart(id, ComponentRegistry.REGISTRY_ID);
     96        return StringUtils.removeStart(id, ComponentRegistry.REGISTRY_ID);
    8397    }
    8498
    8599    protected static void enrichSpecHeader(CMDComponentSpec spec, AbstractDescription description) {
    86         Header header = spec.getHeader();
    87         header.setID(description.getId());
    88         if (StringUtils.isEmpty(header.getName())) {
    89             header.setName(description.getName());
    90         }
    91         if (StringUtils.isEmpty(header.getDescription())) {
    92             header.setDescription(description.getDescription());
    93         }
     100        Header header = spec.getHeader();
     101        header.setID(description.getId());
     102        if (StringUtils.isEmpty(header.getName())) {
     103            header.setName(description.getName());
     104        }
     105        if (StringUtils.isEmpty(header.getDescription())) {
     106            header.setDescription(description.getDescription());
     107        }
    94108    }
    95109
    96110    protected static boolean findComponentId(String componentId, List<CMDComponentType> componentReferences) {
    97         for (CMDComponentType cmdComponent : componentReferences) {
    98             if (componentId.equals(cmdComponent.getComponentId())) {
    99                 return true;
    100             } else if (findComponentId(componentId, cmdComponent.getCMDComponent())) {
    101                 return true;
    102             }
    103         }
    104         return false;
     111        for (CMDComponentType cmdComponent : componentReferences) {
     112            if (componentId.equals(cmdComponent.getComponentId())) {
     113                return true;
     114            } else if (findComponentId(componentId, cmdComponent.getCMDComponent())) {
     115                return true;
     116            }
     117        }
     118        return false;
    105119    }
    106120
    107121    protected static void writeXsd(CMDComponentSpec expandedSpec, OutputStream outputStream) {
    108         MDMarshaller.generateXsd(expandedSpec, outputStream);
     122        MDMarshaller.generateXsd(expandedSpec, outputStream);
    109123    }
    110124
    111125    protected static void writeXml(CMDComponentSpec spec, OutputStream outputStream) {
    112         try {
    113             MDMarshaller.marshal(spec, outputStream);
    114         } catch (UnsupportedEncodingException e) {
    115             LOG.error("Error in encoding: ", e);
    116         } catch (JAXBException e) {
    117             LOG.error("Cannot marshall spec: " + spec, e);
    118         }
     126        try {
     127            MDMarshaller.marshal(spec, outputStream);
     128        } catch (UnsupportedEncodingException e) {
     129            LOG.error("Error in encoding: ", e);
     130        } catch (JAXBException e) {
     131            LOG.error("Cannot marshall spec: " + spec, e);
     132        }
    119133    }
    120134
    121135    protected void checkStillUsed(String componentId) throws DeleteFailedException, ComponentRegistryException {
    122         List<ProfileDescription> profiles = getUsageInProfiles(componentId);
    123         List<ComponentDescription> components = getUsageInComponents(componentId);
    124         if (!profiles.isEmpty() || !components.isEmpty()) {
    125             throw new DeleteFailedException(createStillInUseMessage(profiles, components));
    126         }
     136        List<ProfileDescription> profiles = getUsageInProfiles(componentId);
     137        List<ComponentDescription> components = getUsageInComponents(componentId);
     138        if (!profiles.isEmpty() || !components.isEmpty()) {
     139            throw new DeleteFailedException(createStillInUseMessage(profiles, components));
     140        }
    127141    }
    128142
    129143    private String createStillInUseMessage(List<ProfileDescription> profiles, List<ComponentDescription> components) {
    130         StringBuilder result = new StringBuilder();
    131         if (!profiles.isEmpty()) {
    132             result.append("Still used by the following profiles: \n");
    133             for (ProfileDescription profileDescription : profiles) {
    134                 result.append(" - ").append(profileDescription.getName()).append("\n");
    135             }
    136         }
    137         if (!components.isEmpty()) {
    138             result.append("Still used by the following components: \n");
    139             for (ComponentDescription componentDescription : components) {
    140                 result.append(" - ").append(componentDescription.getName()).append("\n");
    141             }
    142         }
    143         result.append("Try to change above mentioned references first.");
    144         return result.toString();
     144        StringBuilder result = new StringBuilder();
     145        if (!profiles.isEmpty()) {
     146            result.append("Still used by the following profiles: \n");
     147            for (ProfileDescription profileDescription : profiles) {
     148                result.append(" - ").append(profileDescription.getName()).append("\n");
     149            }
     150        }
     151        if (!components.isEmpty()) {
     152            result.append("Still used by the following components: \n");
     153            for (ComponentDescription componentDescription : components) {
     154                result.append(" - ").append(componentDescription.getName()).append("\n");
     155            }
     156        }
     157        result.append("Try to change above mentioned references first.");
     158        return result.toString();
    145159    }
    146160}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/CMDComponentSpecExpanderDbImpl.java

    r1359 r1631  
    1414
    1515    public CMDComponentSpecExpanderDbImpl(ComponentRegistryDbImpl registry) {
    16         super(registry);
    17         dbImplRegistry = registry;
     16        super(registry);
     17        dbImplRegistry = registry;
    1818    }
    1919
    2020    public static CMDComponentSpec expandComponent(String componentId, ComponentRegistryDbImpl registry) throws ComponentRegistryException {
    21         CMDComponentSpecExpanderDbImpl expander = new CMDComponentSpecExpanderDbImpl(registry);
    22         return expander.expandComponent(componentId);
     21        CMDComponentSpecExpanderDbImpl expander = new CMDComponentSpecExpanderDbImpl(registry);
     22        return expander.expandComponent(componentId);
    2323    }
    2424
    2525    public static CMDComponentSpec expandProfile(String profileId, ComponentRegistryDbImpl registry) throws ComponentRegistryException {
    26         CMDComponentSpecExpanderDbImpl expander = new CMDComponentSpecExpanderDbImpl(registry);
    27         return expander.expandProfile(profileId);
     26        CMDComponentSpecExpanderDbImpl expander = new CMDComponentSpecExpanderDbImpl(registry);
     27        return expander.expandProfile(profileId);
    2828    }
    2929
    3030    @Override
    3131    protected CMDComponentSpec getUncachedComponent(String componentId) throws ComponentRegistryException {
    32         return dbImplRegistry.getUncachedMDComponent(componentId);
     32        return dbImplRegistry.getUncachedMDComponent(componentId);
    3333    }
    3434
    3535    @Override
    3636    protected CMDComponentSpec getUncachedProfile(String profileId) throws ComponentRegistryException {
    37         return dbImplRegistry.getUncachedMDProfile(profileId);
     37        return dbImplRegistry.getUncachedMDProfile(profileId);
    3838    }
    3939}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDao.java

    r1319 r1631  
    1212public abstract class ComponentRegistryDao<T> extends SimpleJdbcDaoSupport {
    1313
    14     public final static String DATABASE_NAME = "component_registry";
     14
     15    public final static String TABLE_COMMENTS = "comments";
    1516    public final static String TABLE_COMPONENT_DESCRIPTION = "component_description";
    1617    public final static String TABLE_PROFILE_DESCRIPTION = "profile_description";
     
    1819    public final static String TABLE_REGISTRY_USER = "registry_user";
    1920    public final static String COLUMN_ID = "id";
     21   
    2022
    2123    public ComponentRegistryDao() {
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r1604 r1631  
    2929import clarin.cmdi.componentregistry.impl.ComponentRegistryImplBase;
    3030import clarin.cmdi.componentregistry.model.AbstractDescription;
     31import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
    3132import clarin.cmdi.componentregistry.model.ComponentDescription;
    3233import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    4950    @Autowired
    5051    private ComponentDescriptionDao componentDescriptionDao;
    51     @Autowired
     52    @Autowired   
    5253    private UserDao userDao;
    5354    @Autowired
     
    5758    @Qualifier("profilesCache")
    5859    private CMDComponentSpecCache profilesCache;
     60    @Autowired
     61    private CommentsDao commentsDao;
     62    //private CMDComponentSpecCache commentsCache;
    5963
    6064    /**
     
    7680     */
    7781    public ComponentRegistryDbImpl(Number userId) {
    78         this.userId = userId;
     82        this.userId = userId;
    7983    }
    8084
    8185    @Override
    8286    public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException {
    83         try {
    84             if (isPublic()) {
    85                 return profileDescriptionDao.getPublicProfileDescriptions();
    86             } else {
    87                 return profileDescriptionDao.getUserspaceDescriptions(getUserId());
    88             }
    89         } catch (DataAccessException ex) {
    90             throw new ComponentRegistryException("Database access error while trying to get profile descriptions", ex);
    91         }
    92     }
    93    
     87        try {
     88            if (isPublic()) {
     89                return profileDescriptionDao.getPublicProfileDescriptions();
     90            } else {
     91                return profileDescriptionDao.getUserspaceDescriptions(getUserId());
     92            }
     93        } catch (DataAccessException ex) {
     94            throw new ComponentRegistryException("Database access error while trying to get profile descriptions", ex);
     95        }
     96    }
     97
    9498    @Override
    9599    public ProfileDescription getProfileDescription(String id) throws ComponentRegistryException {
    96         try {
    97             return profileDescriptionDao.getByCmdId(id, getUserId());
    98         } catch (DataAccessException ex) {
    99             throw new ComponentRegistryException("Database access error while trying to get profile description", ex);
    100         }
     100        try {
     101            return profileDescriptionDao.getByCmdId(id, getUserId());
     102        } catch (DataAccessException ex) {
     103            throw new ComponentRegistryException("Database access error while trying to get profile description", ex);
     104        }
    101105    }
    102106
    103107    @Override
    104108    public List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException {
    105         try {
    106             if (isPublic()) {
    107                 return componentDescriptionDao.getPublicComponentDescriptions();
    108             } else {
    109                 return componentDescriptionDao.getUserspaceDescriptions(getUserId());
    110             }
    111         } catch (DataAccessException ex) {
    112             throw new ComponentRegistryException("Database access error while trying to get component descriptions", ex);
    113         }
     109        try {
     110            if (isPublic()) {
     111                return componentDescriptionDao.getPublicComponentDescriptions();
     112            } else {
     113                return componentDescriptionDao.getUserspaceDescriptions(getUserId());
     114            }
     115        } catch (DataAccessException ex) {
     116            throw new ComponentRegistryException("Database access error while trying to get component descriptions", ex);
     117        }
    114118    }
    115119
    116120    @Override
    117121    public ComponentDescription getComponentDescription(String id) throws ComponentRegistryException {
    118         try {
    119             return componentDescriptionDao.getByCmdId(id, getUserId());
    120         } catch (DataAccessException ex) {
    121             throw new ComponentRegistryException("Database access error while trying to get component description", ex);
    122         }
    123     }
     122        try {
     123            return componentDescriptionDao.getByCmdId(id, getUserId());
     124        } catch (DataAccessException ex) {
     125            throw new ComponentRegistryException("Database access error while trying to get component description", ex);
     126        }
     127    }
     128
     129    @Override
     130    public List<Comment> getCommentsInProfile(String profileId) throws ComponentRegistryException {
     131        try {
     132            return commentsDao.getCommentsFromProfile(profileId);
     133        } catch (DataAccessException ex) {
     134            throw new ComponentRegistryException("Database access error while trying to get comment from profile", ex);
     135        }
     136    }
     137
     138    @Override
     139    public Comment getSpecifiedCommentInProfile(String commentId) throws ComponentRegistryException {
     140        try {
     141            return commentsDao.getSpecifiedCommentFromProfile(commentId);
     142        } catch (DataAccessException ex) {
     143            throw new ComponentRegistryException("Database access error while trying to get comment from component", ex);
     144        }
     145    }
     146
     147    @Override
     148    public List<Comment> getCommentsInComponent(String componentId) throws ComponentRegistryException {
     149        try {
     150            return commentsDao.getCommentsFromComponent(componentId);
     151        } catch (DataAccessException ex) {
     152            throw new ComponentRegistryException("Database access error while trying to get comment from component", ex);
     153        }
     154    }
     155
     156    @Override
     157    public Comment getSpecifiedCommentInComponent(String commentId) throws ComponentRegistryException {
     158        try {
     159            return commentsDao.getSpecifiedCommentFromComponent(commentId);
     160        } catch (DataAccessException ex) {
     161            throw new ComponentRegistryException("Database access error while trying to get comment from component", ex);
     162        }
     163    }
     164
     165//    @Override
     166//    public List<Comment> getComments() throws ComponentRegistryException {
     167//        throw new UnsupportedOperationException("Not supported yet.");
     168//    }
    124169
    125170    @Override
    126171    public CMDComponentSpec getMDProfile(String id) throws ComponentRegistryException {
    127         if (inWorkspace(profileDescriptionDao, id)) {
    128             CMDComponentSpec result = profilesCache.get(id);
    129             if (result == null && !profilesCache.containsKey(id)) {
    130                 result = getUncachedMDProfile(id);
    131                 profilesCache.put(id, result);
    132             }
    133             return result;
    134         } else {
    135             // May exist, but not in this workspace
    136             return null;
    137         }
     172        if (inWorkspace(profileDescriptionDao, id)) {
     173            CMDComponentSpec result = profilesCache.get(id);
     174            if (result == null && !profilesCache.containsKey(id)) {
     175                result = getUncachedMDProfile(id);
     176                profilesCache.put(id, result);
     177            }
     178            return result;
     179        } else {
     180            // May exist, but not in this workspace
     181            return null;
     182        }
    138183    }
    139184
    140185    public CMDComponentSpec getUncachedMDProfile(String id) throws ComponentRegistryException {
    141         try {
    142             return getUncachedMDComponent(id, profileDescriptionDao);
    143         } catch (DataAccessException ex) {
    144             throw new ComponentRegistryException("Database access error while trying to get profile", ex);
    145         }
     186        try {
     187            return getUncachedMDComponent(id, profileDescriptionDao);
     188        } catch (DataAccessException ex) {
     189            throw new ComponentRegistryException("Database access error while trying to get profile", ex);
     190        }
    146191    }
    147192
    148193    @Override
    149194    public CMDComponentSpec getMDComponent(String id) throws ComponentRegistryException {
    150         if (inWorkspace(componentDescriptionDao, id)) {
    151             CMDComponentSpec result = componentsCache.get(id);
    152             if (result == null && !componentsCache.containsKey(id)) {
    153                 result = getUncachedMDComponent(id);
    154                 componentsCache.put(id, result);
    155             }
    156             return result;
    157         } else {
    158             return null;
    159         }
     195        if (inWorkspace(componentDescriptionDao, id)) {
     196            CMDComponentSpec result = componentsCache.get(id);
     197            if (result == null && !componentsCache.containsKey(id)) {
     198                result = getUncachedMDComponent(id);
     199                componentsCache.put(id, result);
     200            }
     201            return result;
     202        } else {
     203            return null;
     204        }
    160205    }
    161206
    162207    public CMDComponentSpec getUncachedMDComponent(String id) throws ComponentRegistryException {
    163         try {
    164             return getUncachedMDComponent(id, componentDescriptionDao);
    165         } catch (DataAccessException ex) {
    166             throw new ComponentRegistryException("Database access error while trying to get component", ex);
    167         }
    168     }
     208        try {
     209            return getUncachedMDComponent(id, componentDescriptionDao);
     210        } catch (DataAccessException ex) {
     211            throw new ComponentRegistryException("Database access error while trying to get component", ex);
     212        }
     213    }
     214
     215////    @Override
     216////    public CMDComponentSpec getMDComment(String id) throws ComponentRegistryException {
     217//////        if (inWorkspace(commentsDao, id)) {
     218//////            CMDComponentSpec result = commentsCache.get(id);
     219//////            if (result == null && !commentsCache.containsKey(id)) {
     220//////                result = getUncachedMDComment(id);
     221//////                commentsCache.put(id, result);
     222//////            }
     223//////            return result;
     224//////        } else {
     225//////            // May exist, but not in this workspace
     226////            return null;
     227//////       }
     228////    }
     229//
     230////    public CMDComponentSpec getUncachedMDComment(String id) throws ComponentRegistryException {
     231////        try {
     232////            return getUncachedMDComment(id, commentsDao);
     233////        } catch (DataAccessException ex) {
     234////            throw new ComponentRegistryException("Database access error while trying to get component", ex);
     235//       }
     236//  }
    169237
    170238    @Override
    171239    public int register(AbstractDescription description, CMDComponentSpec spec) {
    172         enrichSpecHeader(spec, description);
    173         try {
    174             String xml = componentSpecToString(spec);
    175             // Convert principal name to user record id
    176             Number uid = convertUserIdInDescription(description);
    177             getDaoForDescription(description).insertDescription(description, xml, isPublic(), uid);
    178             invalidateCache(description);
    179             return 0;
    180         } catch (DataAccessException ex) {
    181             LOG.error("Database error while registering component", ex);
    182             return -1;
    183         } catch (JAXBException ex) {
    184             LOG.error("Error while registering component", ex);
    185             return -2;
    186         } catch (UnsupportedEncodingException ex) {
    187             LOG.error("Error while registering component", ex);
    188             return -3;
    189         }
     240        enrichSpecHeader(spec, description);
     241        try {
     242            String xml = componentSpecToString(spec);
     243            // Convert principal name to user record id
     244            Number uid = convertUserIdInDescription(description);
     245            getDaoForDescription(description).insertDescription(description, xml, isPublic(), uid);
     246            invalidateCache(description);
     247            return 0;
     248        } catch (DataAccessException ex) {
     249            LOG.error("Database error while registering component", ex);
     250            return -1;
     251        } catch (JAXBException ex) {
     252            LOG.error("Error while registering component", ex);
     253            return -2;
     254        } catch (UnsupportedEncodingException ex) {
     255            LOG.error("Error while registering component", ex);
     256            return -3;
     257        }
    190258    }
    191259
     
    201269     */
    202270    private Number convertUserIdInDescription(AbstractDescription description) throws DataAccessException {
    203         Number uid = null;
    204         if (description.getUserId() != null) {
    205             User user = userDao.getByPrincipalName(description.getUserId());
    206             if (user != null) {
    207                 uid = user.getId();
    208             }
    209         } else {
    210             uid = userId;
    211         }
    212         if (uid != null) {
    213             description.setUserId(uid.toString());
    214         }
    215         return uid;
     271        Number uid = null;
     272        if (description.getUserId() != null) {
     273            User user = userDao.getByPrincipalName(description.getUserId());
     274            if (user != null) {
     275                uid = user.getId();
     276            }
     277        } else {
     278            uid = userId;
     279        }
     280        if (uid != null) {
     281            description.setUserId(uid.toString());
     282        }
     283        return uid;
    216284    }
    217285
    218286    @Override
    219287    public int update(AbstractDescription description, CMDComponentSpec spec, Principal principal, boolean forceUpdate) {
    220         try {
    221             checkAuthorisation(description, principal);
    222             checkAge(description, principal);
    223             // For public components, check if used in other components or profiles (unless forced)
    224             if (!forceUpdate && this.isPublic() && !description.isProfile()) {
    225                 checkStillUsed(description.getId());
    226             }
    227             AbstractDescriptionDao<?> dao = getDaoForDescription(description);
    228             dao.updateDescription(getIdForDescription(description), description, componentSpecToString(spec));
    229             invalidateCache(description);
    230             return 0;
    231         } catch (JAXBException ex) {
    232             LOG.error("Error while updating component", ex);
    233             return -1;
    234         } catch (UnsupportedEncodingException ex) {
    235             LOG.error("Error while updating component", ex);
    236             return -1;
    237         } catch (IllegalArgumentException ex) {
    238             LOG.error("Error while updating component", ex);
    239             return -1;
    240         } catch (UserUnauthorizedException e) {
    241             LOG.error("Error while updating component", e);
    242             return -1;
    243         } catch (DeleteFailedException e) {
    244             LOG.error("Error while updating component", e);
    245             return -1;
    246         } catch (ComponentRegistryException e) {
    247             LOG.error("Error while updating component", e);
    248             return -1;
    249         }
     288        try {
     289            checkAuthorisation(description, principal);
     290            checkAge(description, principal);
     291            // For public components, check if used in other components or profiles (unless forced)
     292            if (!forceUpdate && this.isPublic() && !description.isProfile()) {
     293                checkStillUsed(description.getId());
     294            }
     295            AbstractDescriptionDao<?> dao = getDaoForDescription(description);
     296            dao.updateDescription(getIdForDescription(description), description, componentSpecToString(spec));
     297            invalidateCache(description);
     298            return 0;
     299        } catch (JAXBException ex) {
     300            LOG.error("Error while updating component", ex);
     301            return -1;
     302        } catch (UnsupportedEncodingException ex) {
     303            LOG.error("Error while updating component", ex);
     304            return -1;
     305        } catch (IllegalArgumentException ex) {
     306            LOG.error("Error while updating component", ex);
     307            return -1;
     308        } catch (UserUnauthorizedException e) {
     309            LOG.error("Error while updating component", e);
     310            return -1;
     311        } catch (DeleteFailedException e) {
     312            LOG.error("Error while updating component", e);
     313            return -1;
     314        } catch (ComponentRegistryException e) {
     315            LOG.error("Error while updating component", e);
     316            return -1;
     317        }
    250318    }
    251319
    252320    @Override
    253321    public int publish(AbstractDescription desc, CMDComponentSpec spec, Principal principal) {
    254         int result = 0;
    255         AbstractDescriptionDao<?> dao = getDaoForDescription(desc);
    256         if (!isPublic()) { // if already in public workspace there is nothing todo
    257             desc.setHref(AbstractDescription.createPublicHref(desc.getHref()));
    258             Number id = getIdForDescription(desc);
    259             try {
    260                 // Update description & content
    261                 dao.updateDescription(id, desc, componentSpecToString(spec));
    262                 // Set to public
    263                 dao.setPublished(id, true);
    264             } catch (DataAccessException ex) {
    265                 LOG.error("Database error while updating component", ex);
    266                 return -1;
    267             } catch (JAXBException ex) {
    268                 LOG.error("Error while updating component", ex);
    269                 return -2;
    270             } catch (UnsupportedEncodingException ex) {
    271                 LOG.error("Error while updating component", ex);
    272                 return -3;
    273             }
    274         }
    275         return result;
     322        int result = 0;
     323        AbstractDescriptionDao<?> dao = getDaoForDescription(desc);
     324        if (!isPublic()) { // if already in public workspace there is nothing todo
     325            desc.setHref(AbstractDescription.createPublicHref(desc.getHref()));
     326            Number id = getIdForDescription(desc);
     327            try {
     328                // Update description & content
     329                dao.updateDescription(id, desc, componentSpecToString(spec));
     330                // Set to public
     331                dao.setPublished(id, true);
     332            } catch (DataAccessException ex) {
     333                LOG.error("Database error while updating component", ex);
     334                return -1;
     335            } catch (JAXBException ex) {
     336                LOG.error("Error while updating component", ex);
     337                return -2;
     338            } catch (UnsupportedEncodingException ex) {
     339                LOG.error("Error while updating component", ex);
     340                return -3;
     341            }
     342        }
     343        return result;
    276344    }
    277345
    278346    @Override
    279347    public void getMDProfileAsXml(String profileId, OutputStream output) throws ComponentRegistryException {
    280         CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandProfile(profileId, this);
    281         writeXml(expandedSpec, output);
     348        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandProfile(profileId, this);
     349        writeXml(expandedSpec, output);
    282350    }
    283351
    284352    @Override
    285353    public void getMDProfileAsXsd(String profileId, OutputStream outputStream) throws ComponentRegistryException {
    286         CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandProfile(profileId, this);
    287         writeXsd(expandedSpec, outputStream);
     354        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandProfile(profileId, this);
     355        writeXsd(expandedSpec, outputStream);
    288356    }
    289357
    290358    @Override
    291359    public void getMDComponentAsXml(String componentId, OutputStream output) throws ComponentRegistryException {
    292         CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandComponent(componentId, this);
    293         writeXml(expandedSpec, output);
     360        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandComponent(componentId, this);
     361        writeXml(expandedSpec, output);
    294362    }
    295363
    296364    @Override
    297365    public void getMDComponentAsXsd(String componentId, OutputStream outputStream) throws ComponentRegistryException {
    298         CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandComponent(componentId, this);
    299         writeXsd(expandedSpec, outputStream);
     366        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandComponent(componentId, this);
     367        writeXsd(expandedSpec, outputStream);
    300368    }
    301369
    302370    @Override
    303371    public void deleteMDProfile(String profileId, Principal principal) throws UserUnauthorizedException, DeleteFailedException,
    304             ComponentRegistryException {
    305         ProfileDescription desc = getProfileDescription(profileId);
    306         if (desc != null) {
    307             try {
    308                 checkAuthorisation(desc, principal);
    309                 checkAge(desc, principal);
    310                 profileDescriptionDao.setDeleted(desc, true);
    311                 invalidateCache(desc);
    312             } catch (DataAccessException ex) {
    313                 throw new DeleteFailedException("Database access error while trying to delete profile", ex);
    314             }
    315         }
    316     }
     372            ComponentRegistryException {
     373        ProfileDescription desc = getProfileDescription(profileId);
     374        if (desc != null) {
     375            try {
     376                checkAuthorisation(desc, principal);
     377                checkAge(desc, principal);
     378                profileDescriptionDao.setDeleted(desc, true);
     379                invalidateCache(desc);
     380            } catch (DataAccessException ex) {
     381                throw new DeleteFailedException("Database access error while trying to delete profile", ex);
     382            }
     383        }
     384    }
     385   
     386//    public void deleteMDComment(String commentId, Principal principal) throws UserUnauthorizedException, DeleteFailedException, ComponentRegistryException {
     387//        Comment desc = getCommentsInComponent(commentId);
     388//        if(desc != null) {
     389//            try {
     390//                checkAuthorisationComment(desc, principal);
     391//                checkCommentAge(desc, principal);
     392//                commentsDao.setDeleted(desc, true);
     393//                invalidateCommentCache(desc);
     394//            } catch (DataAccessException ex) {
     395//                throw new DeleteFailedException("Database access error while trying to delete profile", ex);
     396//            }
     397//        }
     398//    }
    317399
    318400    @Override
    319401    public void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws UserUnauthorizedException,
    320             DeleteFailedException, ComponentRegistryException {
    321         ComponentDescription desc = componentDescriptionDao.getByCmdId(componentId);
    322         if (desc != null) {
    323             try {
    324                 checkAuthorisation(desc, principal);
    325                 checkAge(desc, principal);
    326 
    327                 if (!forceDelete) {
    328                     checkStillUsed(componentId);
    329                 }
    330                 componentDescriptionDao.setDeleted(desc, true);
    331                 invalidateCache(desc);
    332             } catch (DataAccessException ex) {
    333                 throw new DeleteFailedException("Database access error while trying to delete component", ex);
    334             }
    335         }
     402            DeleteFailedException, ComponentRegistryException {
     403        ComponentDescription desc = componentDescriptionDao.getByCmdId(componentId);
     404        if (desc != null) {
     405            try {
     406                checkAuthorisation(desc, principal);
     407                checkAge(desc, principal);
     408
     409                if (!forceDelete) {
     410                    checkStillUsed(componentId);
     411                }
     412                componentDescriptionDao.setDeleted(desc, true);
     413                invalidateCache(desc);
     414            } catch (DataAccessException ex) {
     415                throw new DeleteFailedException("Database access error while trying to delete component", ex);
     416            }
     417        }
    336418    }
    337419
    338420    @Override
    339421    public boolean isPublic() {
    340         return null == userId;
     422        return null == userId;
    341423    }
    342424
    343425    public void setPublic() {
    344         this.userId = null;
     426        this.userId = null;
    345427    }
    346428
     
    349431     */
    350432    public Number getUserId() {
    351         return userId;
     433        return userId;
    352434    }
    353435
     
    358440     */
    359441    public void setUserId(Number user) {
    360         this.userId = user;
     442        this.userId = user;
    361443    }
    362444
    363445    private void invalidateCache(AbstractDescription description) {
    364         if (description.isProfile()) {
    365             profilesCache.remove(description.getId());
    366         } else {
    367             componentsCache.remove(description.getId());
    368         }
    369     }
     446        if (description.isProfile()) {
     447            profilesCache.remove(description.getId());
     448        } else {
     449            componentsCache.remove(description.getId());
     450        }
     451    }
     452   
     453//        private void invalidateCommentCache(Comment comment) {
     454//            commentsCache.remove(comment.getId());
     455//    }
    370456
    371457    private AbstractDescriptionDao<?> getDaoForDescription(AbstractDescription description) {
    372         return description.isProfile() ? profileDescriptionDao : componentDescriptionDao;
    373     }
     458        return description.isProfile() ? profileDescriptionDao : componentDescriptionDao;
     459    }
     460   
     461//    private CommentsDao getDaoForCommentDescription(Comment comment) {
     462//        return commentsDao;
     463//    }
    374464
    375465    /**
     
    384474     */
    385475    private Number getIdForDescription(AbstractDescription description) throws IllegalArgumentException {
    386         Number dbId = null;
    387         AbstractDescriptionDao<?> dao = getDaoForDescription(description);
    388         try {
    389             dbId = dao.getDbId(description.getId());
    390         } catch (DataAccessException ex) {
    391             LOG.error("Error getting dbId for component with id " + description.getId(), ex);
    392         }
    393         if (dbId == null) {
    394             throw new IllegalArgumentException("Could not get database Id for description");
    395         } else {
    396             return dbId;
    397         }
    398     }
    399 
     476        Number dbId = null;
     477        AbstractDescriptionDao<?> dao = getDaoForDescription(description);
     478        try {
     479            dbId = dao.getDbId(description.getId());
     480        } catch (DataAccessException ex) {
     481            LOG.error("Error getting dbId for component with id " + description.getId(), ex);
     482        }
     483        if (dbId == null) {
     484            throw new IllegalArgumentException("Could not get database Id for description");
     485        } else {
     486            return dbId;
     487        }
     488    }
     489
     490   
     491//        private Number getIdForCommentDescription(Comment comment) throws IllegalArgumentException {
     492//        Number dbId = null;
     493//        CommentsDao dao = getDaoForCommentDescription(comment);
     494//        try {
     495//            dbId = dao.getDbId(comment.getId());
     496//        } catch (DataAccessException ex) {
     497//            LOG.error("Error getting dbId for comment with id " + comment.getId(), ex);
     498//        }
     499//        if (dbId == null) {
     500//            throw new IllegalArgumentException("Could not get database Id for description");
     501//        } else {
     502//            return dbId;
     503//        }
     504//    }
     505   
    400506    private String componentSpecToString(CMDComponentSpec spec) throws UnsupportedEncodingException, JAXBException {
    401         ByteArrayOutputStream os = new ByteArrayOutputStream();
    402         MDMarshaller.marshal(spec, os);
    403         String xml = os.toString("UTF-8");
    404         return xml;
     507        ByteArrayOutputStream os = new ByteArrayOutputStream();
     508        MDMarshaller.marshal(spec, os);
     509        String xml = os.toString("UTF-8");
     510        return xml;
    405511    }
    406512
    407513    private CMDComponentSpec getUncachedMDComponent(String id, AbstractDescriptionDao dao) {
    408         String xml = dao.getContent(false, id);
    409         if (xml != null) {
    410             try {
    411                 InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
    412                 return MDMarshaller.unmarshal(CMDComponentSpec.class, is, null);
    413 
    414             } catch (JAXBException ex) {
    415                 LOG.error(null, ex);
    416             } catch(UnsupportedEncodingException ex){
    417                 LOG.error(null, ex);
    418             }
    419         }
    420         return null;
    421     }
     514        String xml = dao.getContent(false, id);
     515        if (xml != null) {
     516            try {
     517                InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
     518                return MDMarshaller.unmarshal(CMDComponentSpec.class, is, null);
     519
     520            } catch (JAXBException ex) {
     521                LOG.error(null, ex);
     522            } catch (UnsupportedEncodingException ex) {
     523                LOG.error(null, ex);
     524            }
     525        }
     526        return null;
     527    }
     528
     529//    private CMDComponentSpec getUncachedMDComment(String id, CommentsDao dao) {
     530//        String xml = dao.getContent(false, id);
     531//        if (xml != null) {
     532//            try {
     533//                InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
     534//                return MDMarshaller.unmarshal(CMDComponentSpec.class, is, null);
     535//
     536//            } catch (JAXBException ex) {
     537//                LOG.error(null, ex);
     538//            } catch (UnsupportedEncodingException ex) {
     539//                LOG.error(null, ex);
     540//            }
     541//        }
     542//        return null;
     543//    }
    422544
    423545    private void checkAuthorisation(AbstractDescription desc, Principal principal) throws UserUnauthorizedException {
    424         if (!isOwnerOfDescription(desc, principal.getName()) && !configuration.isAdminUser(principal)) {
    425             throw new UserUnauthorizedException("Unauthorized operation user '" + principal.getName()
    426                     + "' is not the creator (nor an administrator) of the " + (desc.isProfile() ? "profile" : "component") + "(" + desc
    427                     + ").");
    428         }
    429     }
     546        if (!isOwnerOfDescription(desc, principal.getName()) && !configuration.isAdminUser(principal)) {
     547            throw new UserUnauthorizedException("Unauthorized operation user '" + principal.getName()
     548                    + "' is not the creator (nor an administrator) of the " + (desc.isProfile() ? "profile" : "component") + "(" + desc
     549                    + ").");
     550        }
     551    }
     552   
     553//    private void checkAuthorisationComment(Comment desc, Principal principal)throws UserUnauthorizedException {
     554//        if (!isOwnerOfComment(desc, principal.getName()) && !configuration.isAdminUser(principal)) {
     555//            throw new UserUnauthorizedException("Unauthorized operation user '" + principal.getName()
     556//                    + "' is not the creator (nor an administrator) of the " + (desc.getId()) + "(" + desc
     557//                    + ").");
     558//        }
     559//    }
    430560
    431561    private boolean isOwnerOfDescription(AbstractDescription desc, String principalName) {
    432         String owner = getDaoForDescription(desc).getOwnerPrincipalName(getIdForDescription(desc));
    433         return owner != null // If owner is null, no one can be owner
    434                 && principalName.equals(owner);
    435     }
     562        String owner = getDaoForDescription(desc).getOwnerPrincipalName(getIdForDescription(desc));
     563        return owner != null // If owner is null, no one can be owner
     564                && principalName.equals(owner);
     565    }
     566   
     567//        private boolean isOwnerOfComment(Comment desc, String principalName) {
     568//        String owner = getDaoForCommentDescription(desc).getOwnerPrincipalName(getIdForCommentDescription(desc));
     569//        return owner != null // If owner is null, no one can be owner
     570//                && principalName.equals(owner);
     571//    }
    436572
    437573    private void checkAge(AbstractDescription desc, Principal principal) throws DeleteFailedException {
    438         if (isPublic() && !configuration.isAdminUser(principal)) {
    439             try {
    440                 Date regDate = AbstractDescription.getDate(desc.getRegistrationDate());
    441                 Calendar calendar = Calendar.getInstance();
    442                 calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
    443                 if (regDate.before(calendar.getTime())) { // More then month old
    444                     throw new DeleteFailedException(
    445                             "The "
    446                                     + (desc.isProfile() ? "Profile" : "Component")
    447                                     + " is more then a month old and cannot be deleted anymore. It might have been used to create metadata, deleting it would invalidate that metadata.");
    448                 }
    449             } catch (ParseException e) {
    450                 LOG.error("Cannot parse date of " + desc + " Error:" + e);
    451             }
    452         }
    453     }
     574        if (isPublic() && !configuration.isAdminUser(principal)) {
     575            try {
     576                Date regDate = AbstractDescription.getDate(desc.getRegistrationDate());
     577                Calendar calendar = Calendar.getInstance();
     578                calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
     579                if (regDate.before(calendar.getTime())) { // More then month old
     580                    throw new DeleteFailedException(
     581                            "The "
     582                            + (desc.isProfile() ? "Profile" : "Component")
     583                            + " is more then a month old and cannot be deleted anymore. It might have been used to create metadata, deleting it would invalidate that metadata.");
     584                }
     585            } catch (ParseException e) {
     586                LOG.error("Cannot parse date of " + desc + " Error:" + e);
     587            }
     588        }
     589    }
     590   
     591//        private void checkCommentAge(Comment desc, Principal principal) throws DeleteFailedException {
     592//        if (isPublic() && !configuration.isAdminUser(principal)) {
     593//            try {
     594//                Date regDate = Comment.getDate(desc.getCommentDate());
     595//                Calendar calendar = Calendar.getInstance();
     596//                calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
     597//                if (regDate.before(calendar.getTime())) { // More then month old
     598//                    throw new DeleteFailedException(
     599//                            "The "
     600//                            + (desc.getId())
     601//                            + " is more then a month old and cannot be deleted anymore.");
     602//                }
     603//            } catch (ParseException e) {
     604//                LOG.error("Cannot parse date of " + desc + " Error:" + e);
     605//            }
     606//        }
     607//    }
    454608
    455609    private boolean inWorkspace(AbstractDescriptionDao<?> dao, String cmdId) {
    456         if (isPublic()) {
    457             return dao.isPublic(cmdId);
    458         } else {
    459             return dao.isInUserSpace(cmdId, getUserId());
    460         }
    461     }
     610        if (isPublic()) {
     611            return dao.isPublic(cmdId);
     612        } else {
     613            return dao.isInUserSpace(cmdId, getUserId());
     614        }
     615    }
     616
     617//    private boolean inWorkspace(CommentsDao dao, String cmdId) {
     618//        if (isPublic()) {
     619//            return dao.isPublic(cmdId);
     620//        } else {
     621//            return dao.isInUserSpace(cmdId, getUserId());
     622//        }
     623//    }
    462624
    463625    @Override
    464626    public String getName() {
    465         if (isPublic()) {
    466             return ComponentRegistry.PUBLIC_NAME;
    467         } else {
    468             return "User " + getUserId() + " Registry";
    469         }
     627        if (isPublic()) {
     628            return ComponentRegistry.PUBLIC_NAME;
     629        } else {
     630            return "User " + getUserId() + " Registry";
     631        }
    470632    }
    471633
    472634    @Override
    473635    public List<ProfileDescription> getDeletedProfileDescriptions() {
    474         return profileDescriptionDao.getDeletedDescriptions(getUserId());
     636        return profileDescriptionDao.getDeletedDescriptions(getUserId());
    475637    }
    476638
    477639    @Override
    478640    public List<ComponentDescription> getDeletedComponentDescriptions() {
    479         return componentDescriptionDao.getDeletedDescriptions(getUserId());
     641        return componentDescriptionDao.getDeletedDescriptions(getUserId());
    480642    }
    481643}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1604 r1631  
    4141import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    4242import clarin.cmdi.componentregistry.model.AbstractDescription;
     43import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
    4344import clarin.cmdi.componentregistry.model.ComponentDescription;
    4445import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    6970
    7071    private ComponentRegistry getRegistry(boolean userspace) {
    71         Principal userPrincipal = security.getUserPrincipal();
    72         UserCredentials userCredentials = getUserCredentials(userPrincipal);
    73         return getRegistry(userspace, userCredentials);
     72        Principal userPrincipal = security.getUserPrincipal();
     73        UserCredentials userCredentials = getUserCredentials(userPrincipal);
     74        return getRegistry(userspace, userCredentials);
    7475    }
    7576
    7677    private ComponentRegistry getRegistry(boolean userspace, UserCredentials userCredentials) {
    77         return componentRegistryFactory.getComponentRegistry(userspace, userCredentials);
     78        return componentRegistryFactory.getComponentRegistry(userspace, userCredentials);
    7879    }
    7980
    8081    private Principal checkAndGetUserPrincipal() {
    81         Principal principal = security.getUserPrincipal();
    82         if (principal == null) {
    83             throw new IllegalArgumentException("no user principal found.");
    84         }
    85         return principal;
     82        Principal principal = security.getUserPrincipal();
     83        if (principal == null) {
     84            throw new IllegalArgumentException("no user principal found.");
     85        }
     86        return principal;
    8687    }
    8788
    8889    private UserCredentials getUserCredentials(Principal userPrincipal) {
    89         UserCredentials userCredentials = null;
    90         if (userPrincipal != null) {
    91             userCredentials = new UserCredentials(userPrincipal);
    92         }
    93         return userCredentials;
     90        UserCredentials userCredentials = null;
     91        if (userPrincipal != null) {
     92            userCredentials = new UserCredentials(userPrincipal);
     93        }
     94        return userCredentials;
    9495    }
    9596
     
    9899    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    99100    public List<ComponentDescription> getRegisteredComponents(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    100         long start = System.currentTimeMillis();
    101         List<ComponentDescription> components = getRegistry(userspace).getComponentDescriptions();
    102         LOG.info("Releasing " + components.size() + " registered components into the world (" + (System.currentTimeMillis() - start)
    103                 + " millisecs)");
    104         return components;
     101        long start = System.currentTimeMillis();
     102        List<ComponentDescription> components = getRegistry(userspace).getComponentDescriptions();
     103        LOG.info("Releasing " + components.size() + " registered components into the world (" + (System.currentTimeMillis() - start)
     104                + " millisecs)");
     105        return components;
    105106    }
    106107
     
    109110    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    110111    public List<ProfileDescription> getRegisteredProfiles(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace,
    111             @QueryParam(METADATA_EDITOR_PARAM) @DefaultValue("false") boolean metadataEditor) throws ComponentRegistryException {
    112         long start = System.currentTimeMillis();
    113        
    114         List<ProfileDescription> profiles;
    115         if (metadataEditor) {
    116             profiles = getRegistry(userspace).getProfileDescriptionsForMetadaEditor();
    117         } else {
    118             profiles = getRegistry(userspace).getProfileDescriptions();
    119         }
    120        
    121         LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start)
    122                 + " millisecs)");
    123         return profiles;
     112            @QueryParam(METADATA_EDITOR_PARAM) @DefaultValue("false") boolean metadataEditor) throws ComponentRegistryException {
     113        long start = System.currentTimeMillis();
     114
     115        List<ProfileDescription> profiles;
     116        if (metadataEditor) {
     117            profiles = getRegistry(userspace).getProfileDescriptionsForMetadaEditor();
     118        } else {
     119            profiles = getRegistry(userspace).getProfileDescriptions();
     120        }
     121
     122        LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start)
     123                + " millisecs)");
     124        return profiles;
    124125    }
    125126
     
    128129    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    129130    public CMDComponentSpec getRegisteredComponent(@PathParam("componentId") String componentId,
    130             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    131         LOG.info("Component with id: " + componentId + " is requested.");
    132         return getRegistry(userspace).getMDComponent(componentId);
     131            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     132        LOG.info("Component with id: " + componentId + " is requested.");
     133        return getRegistry(userspace).getMDComponent(componentId);
    133134    }
    134135
     
    137138    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
    138139    public Response getRegisteredComponentRawType(@PathParam("componentId") final String componentId, @PathParam("rawType") String rawType) {
    139         LOG.info("Component with id: " + componentId + " and rawType:" + rawType + " is requested.");
    140         StreamingOutput result = null;
    141         try {
    142             final ComponentRegistry registry = findRegistry(componentId, new ComponentClosure());
    143             if (registry == null) {
    144                 return Response.status(Status.NOT_FOUND).entity("Id: " + componentId + " is not registered, cannot create data.").build();
    145             }
    146             ComponentDescription desc = registry.getComponentDescription(componentId);
    147             checkAndThrowDescription(desc, componentId);
    148             String fileName = desc.getName() + "." + rawType;
    149             if ("xml".equalsIgnoreCase(rawType)) {
    150                 result = new StreamingOutput() {
    151 
    152                     @Override
    153                     public void write(OutputStream output) throws IOException, WebApplicationException {
    154                         try {
    155                             registry.getMDComponentAsXml(componentId, output);
    156                         } catch (ComponentRegistryException e) {
    157                             LOG.info("Could not retrieve component", e);
    158                             throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    159                         }
    160                     }
    161                 };
    162             } else if ("xsd".equalsIgnoreCase(rawType)) {
    163                 result = new StreamingOutput() {
    164 
    165                     @Override
    166                     public void write(OutputStream output) throws IOException, WebApplicationException {
    167                         try {
    168                             registry.getMDComponentAsXsd(componentId, output);
    169                         } catch (ComponentRegistryException e) {
    170                             LOG.info("Could not retrieve component", e);
    171                             throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    172                         }
    173 
    174                     }
    175                 };
    176             } else {
    177                 throw new WebApplicationException(Response.serverError().entity(
    178                         "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
    179             }
    180             return createDownloadResponse(result, fileName);
    181         } catch (ComponentRegistryException e) {
    182             LOG.info("Could not retrieve component", e);
    183             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    184         }
     140        LOG.info("Component with id: " + componentId + " and rawType:" + rawType + " is requested.");
     141        StreamingOutput result = null;
     142        try {
     143            final ComponentRegistry registry = findRegistry(componentId, new ComponentClosure());
     144            if (registry == null) {
     145                return Response.status(Status.NOT_FOUND).entity("Id: " + componentId + " is not registered, cannot create data.").build();
     146            }
     147            ComponentDescription desc = registry.getComponentDescription(componentId);
     148            checkAndThrowDescription(desc, componentId);
     149            String fileName = desc.getName() + "." + rawType;
     150            if ("xml".equalsIgnoreCase(rawType)) {
     151                result = new StreamingOutput() {
     152
     153                    @Override
     154                    public void write(OutputStream output) throws IOException, WebApplicationException {
     155                        try {
     156                            registry.getMDComponentAsXml(componentId, output);
     157                        } catch (ComponentRegistryException e) {
     158                            LOG.info("Could not retrieve component", e);
     159                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     160                        }
     161                    }
     162                };
     163            } else if ("xsd".equalsIgnoreCase(rawType)) {
     164                result = new StreamingOutput() {
     165
     166                    @Override
     167                    public void write(OutputStream output) throws IOException, WebApplicationException {
     168                        try {
     169                            registry.getMDComponentAsXsd(componentId, output);
     170                        } catch (ComponentRegistryException e) {
     171                            LOG.info("Could not retrieve component", e);
     172                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     173                        }
     174
     175                    }
     176                };
     177            } else {
     178                throw new WebApplicationException(Response.serverError().entity(
     179                        "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
     180            }
     181            return createDownloadResponse(result, fileName);
     182        } catch (ComponentRegistryException e) {
     183            LOG.info("Could not retrieve component", e);
     184            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     185        }
    185186    }
    186187
    187188    public ComponentRegistry findRegistry(String id, RegistryClosure<? extends AbstractDescription> clos) throws ComponentRegistryException {
    188         AbstractDescription desc = null;
    189         ComponentRegistry result = getRegistry(false);
    190         desc = clos.getDescription(result, id);
    191         if (desc == null) {
    192             List<ComponentRegistry> userRegs = componentRegistryFactory.getAllUserRegistries();
    193             for (ComponentRegistry reg : userRegs) {
    194                 desc = clos.getDescription(reg, id);
    195                 if (desc != null) {
    196                     result = reg;
    197                     break;
    198                 }
    199             }
    200         }
    201         return result;
     189        AbstractDescription desc = null;
     190        ComponentRegistry result = getRegistry(false);
     191        desc = clos.getDescription(result, id);
     192        if (desc == null) {
     193            List<ComponentRegistry> userRegs = componentRegistryFactory.getAllUserRegistries();
     194            for (ComponentRegistry reg : userRegs) {
     195                desc = clos.getDescription(reg, id);
     196                if (desc != null) {
     197                    result = reg;
     198                    break;
     199                }
     200            }
     201        }
     202        return result;
    202203    }
    203204
     
    206207    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    207208    public CMDComponentSpec getRegisteredProfile(@PathParam("profileId") String profileId,
    208             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    209         LOG.info("Profile with id: " + profileId + " is requested.");
    210         return getRegistry(userspace).getMDProfile(profileId);
     209            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     210        LOG.info("Profile with id: " + profileId + " is requested.");
     211        return getRegistry(userspace).getMDProfile(profileId);
    211212    }
    212213
     
    215216    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    216217    public List<AbstractDescription> getComponentUsage(@PathParam("componentId") String componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("true") boolean userspace) throws ComponentRegistryException {
    217         try {
    218             final long start = System.currentTimeMillis();
    219             ComponentRegistry registry = getRegistry(userspace);
    220             List<ComponentDescription> components = registry.getUsageInComponents(componentId);
    221             List<ProfileDescription> profiles = registry.getUsageInProfiles(componentId);
    222 
    223             LOG.info("Found " + components.size() + " components and " + profiles.size() + " profiles that use component " + componentId
    224                     + " (" + (System.currentTimeMillis() - start) + " millisecs)");
    225 
    226             List<AbstractDescription> usages = new ArrayList<AbstractDescription>(components.size() + profiles.size());
    227             usages.addAll(components);
    228             usages.addAll(profiles);
    229 
    230             return usages;
    231         } catch (ComponentRegistryException e) {
    232             LOG.info("Could not retrieve profile usage", e);
    233             throw e;
    234         }
     218        try {
     219            final long start = System.currentTimeMillis();
     220            ComponentRegistry registry = getRegistry(userspace);
     221            List<ComponentDescription> components = registry.getUsageInComponents(componentId);
     222            List<ProfileDescription> profiles = registry.getUsageInProfiles(componentId);
     223
     224            LOG.info("Found " + components.size() + " components and " + profiles.size() + " profiles that use component " + componentId
     225                    + " (" + (System.currentTimeMillis() - start) + " millisecs)");
     226
     227            List<AbstractDescription> usages = new ArrayList<AbstractDescription>(components.size() + profiles.size());
     228            usages.addAll(components);
     229            usages.addAll(profiles);
     230
     231            return usages;
     232        } catch (ComponentRegistryException e) {
     233            LOG.info("Could not retrieve profile usage", e);
     234            throw e;
     235        }
     236    }
     237
     238    @GET
     239    @Path("/profile/{profileId}/comments")
     240    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     241    public List<Comment> getRegisteredCommentsFromProfile(@PathParam("profileId") String profileId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     242        long start = System.currentTimeMillis();
     243        List<Comment> comments = getRegistry(userspace).getCommentsInProfile(profileId);
     244        LOG.info("Releasing " + comments.size() + " registered comments in Profile into the world (" + (System.currentTimeMillis() - start)
     245                + " millisecs)");
     246        return comments;
     247    }
     248
     249    @GET
     250    @Path("/component/{componentId}/comments")
     251    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     252    public List<Comment> getRegisteredCommentsFromComponent(@PathParam("componentId") String componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     253        long start = System.currentTimeMillis();
     254        List<Comment> comments = getRegistry(userspace).getCommentsInComponent(componentId);
     255        LOG.info("Releasing " + comments.size() + " registered comments in Component into the world (" + (System.currentTimeMillis() - start)
     256                + " millisecs)");
     257        return comments;
     258    }
     259
     260    @GET
     261    @Path("/profiles/{profileId}/comments/{commentsId}")
     262    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     263    public Comment getSpecifiedCommentFromProfile(@PathParam("commentId") String commentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     264        long start = System.currentTimeMillis();
     265        LOG.info(" Comments of component with id" + commentId + " are requested.");
     266        return getRegistry(userspace).getSpecifiedCommentInProfile(commentId);
     267    }
     268
     269    @GET
     270    @Path("/component/{componentId}/comments/{commentsId}")
     271    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     272    public Comment getRegisteredCommentFromComponent(@PathParam("commentId") String commentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     273        LOG.info(" Comments of component with id" + commentId + " are requested.");
     274        return getRegistry(userspace).getSpecifiedCommentInComponent(commentId);
    235275    }
    236276
     
    246286    @Path("/profiles/{profileId}")
    247287    public Response manipulateRegisteredProfile(@PathParam("profileId") String profileId, @FormParam("method") String method,
    248             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    249         if ("delete".equalsIgnoreCase(method)) {
    250             return deleteRegisteredProfile(profileId, userspace);
    251         } else {
    252             return Response.ok().build();
    253         }
    254     }
     288            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     289        if ("delete".equalsIgnoreCase(method)) {
     290            return deleteRegisteredProfile(profileId, userspace);
     291        } else {
     292            return Response.ok().build();
     293        }
     294    }
     295
     296//    @POST
     297//    @Path("/profiles/{profileId}/comments/{commentId}")
     298//    public Response manipulateRegisteredCommentFromProfile(@PathParam("profileId") String commentId, @FormParam("method") String method,
     299//            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     300//        if ("delete".equalsIgnoreCase(method)) {
     301//            return deleteRegisteredProfile(commentId, userspace);
     302//        } else {
     303//            return Response.ok().build();
     304//        }
     305//    }
     306//
     307//    @POST
     308//    @Path("/components/{componentId}/comments/{commentId}")
     309//    public Response manipulateRegisteredCommentFromComponent(@PathParam("profileId") String commentId, @FormParam("method") String method,
     310//            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     311//        if ("delete".equalsIgnoreCase(method)) {
     312//            return deleteRegisteredProfile(commentId, userspace);
     313//        } else {
     314//            return Response.ok().build();
     315//        }
     316//    }
    255317
    256318    @POST
     
    258320    @Consumes("multipart/form-data")
    259321    public Response publishRegisteredProfile(@PathParam("profileId") String profileId, @FormDataParam(DATA_FORM_FIELD) InputStream input,
    260             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
    261             @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    262         Principal principal = checkAndGetUserPrincipal();
    263         try {
    264             ProfileDescription desc = getRegistry(true).getProfileDescription(profileId);
    265             if (desc != null) {
    266                 updateDescription(desc, name, description, domainName, group);
    267                 return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
    268             } else {
    269                 LOG.error("Update of nonexistent id (" + profileId + ") failed.");
    270                 return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
    271             }
    272         } catch (ComponentRegistryException e) {
    273             LOG.info("Could not retrieve component", e);
    274             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    275         }
     322            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     323            @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     324        Principal principal = checkAndGetUserPrincipal();
     325        try {
     326            ProfileDescription desc = getRegistry(true).getProfileDescription(profileId);
     327            if (desc != null) {
     328                updateDescription(desc, name, description, domainName, group);
     329                return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
     330            } else {
     331                LOG.error("Update of nonexistent id (" + profileId + ") failed.");
     332                return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
     333            }
     334        } catch (ComponentRegistryException e) {
     335            LOG.info("Could not retrieve component", e);
     336            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     337        }
    276338    }
    277339
     
    280342    @Consumes("multipart/form-data")
    281343    public Response updateRegisteredProfile(@PathParam("profileId") String profileId,
    282             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
    283             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
    284             @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    285         Principal principal = checkAndGetUserPrincipal();
    286         UserCredentials userCredentials = getUserCredentials(principal);
    287         try {
    288             ProfileDescription desc = getRegistry(userspace).getProfileDescription(profileId);
    289             if (desc != null) {
    290                 updateDescription(desc, name, description, domainName, group);
    291                 return register(input, desc, userCredentials, userspace, new UpdateAction(principal));
    292             } else {
    293                 LOG.error("Update of nonexistent id (" + profileId + ") failed.");
    294                 return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
    295             }
    296         } catch (ComponentRegistryException e) {
    297             LOG.info("Could not retrieve component", e);
    298             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    299         }
     344            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
     345            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     346            @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     347        Principal principal = checkAndGetUserPrincipal();
     348        UserCredentials userCredentials = getUserCredentials(principal);
     349        try {
     350            ProfileDescription desc = getRegistry(userspace).getProfileDescription(profileId);
     351            if (desc != null) {
     352                updateDescription(desc, name, description, domainName, group);
     353                return register(input, desc, userCredentials, userspace, new UpdateAction(principal));
     354            } else {
     355                LOG.error("Update of nonexistent id (" + profileId + ") failed.");
     356                return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
     357            }
     358        } catch (ComponentRegistryException e) {
     359            LOG.info("Could not retrieve component", e);
     360            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     361        }
    300362    }
    301363
     
    311373    @Path("/components/{componentId}")
    312374    public Response manipulateRegisteredComponent(@PathParam("componentId") String componentId, @FormParam("method") String method,
    313             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    314         if ("delete".equalsIgnoreCase(method)) {
    315             return deleteRegisteredComponent(componentId, userspace);
    316         } else {
    317             return Response.ok().build();
    318         }
     375            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     376        if ("delete".equalsIgnoreCase(method)) {
     377            return deleteRegisteredComponent(componentId, userspace);
     378        } else {
     379            return Response.ok().build();
     380        }
    319381    }
    320382
     
    323385    @Consumes("multipart/form-data")
    324386    public Response publishRegisteredComponent(@PathParam("componentId") String componentId,
    325             @FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    326             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
    327             @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    328         Principal principal = checkAndGetUserPrincipal();
    329         try {
    330             ComponentDescription desc = getRegistry(true).getComponentDescription(componentId);
    331             if (desc != null) {
    332                 updateDescription(desc, name, description, domainName, group);
    333                 return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
    334             } else {
    335                 LOG.error("Update of nonexistent id (" + componentId + ") failed.");
    336                 return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
    337             }
    338         } catch (ComponentRegistryException e) {
    339             LOG.info("Could not retrieve component", e);
    340             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    341         }
     387            @FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
     388            @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
     389            @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     390        Principal principal = checkAndGetUserPrincipal();
     391        try {
     392            ComponentDescription desc = getRegistry(true).getComponentDescription(componentId);
     393            if (desc != null) {
     394                updateDescription(desc, name, description, domainName, group);
     395                return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
     396            } else {
     397                LOG.error("Update of nonexistent id (" + componentId + ") failed.");
     398                return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
     399            }
     400        } catch (ComponentRegistryException e) {
     401            LOG.info("Could not retrieve component", e);
     402            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     403        }
    342404    }
    343405
     
    346408    @Consumes("multipart/form-data")
    347409    public Response updateRegisteredComponent(@PathParam("componentId") String componentId,
    348             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
    349             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
    350             @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    351         Principal principal = checkAndGetUserPrincipal();
    352         try {
    353             ComponentDescription desc = getRegistry(userspace).getComponentDescription(componentId);
    354             if (desc != null) {
    355                 updateDescription(desc, name, description, domainName, group);
    356                 return register(input, desc, getUserCredentials(principal), userspace, new UpdateAction(principal));
    357             } else {
    358                 LOG.error("Update of nonexistent id (" + componentId + ") failed.");
    359                 return Response.serverError().entity("Invalid id, cannot update nonexistent component").build();
    360             }
    361         } catch (ComponentRegistryException e) {
    362             LOG.info("Could not retrieve component", e);
    363             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    364         }
     410            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
     411            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     412            @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     413        Principal principal = checkAndGetUserPrincipal();
     414        try {
     415            ComponentDescription desc = getRegistry(userspace).getComponentDescription(componentId);
     416            if (desc != null) {
     417                updateDescription(desc, name, description, domainName, group);
     418                return register(input, desc, getUserCredentials(principal), userspace, new UpdateAction(principal));
     419            } else {
     420                LOG.error("Update of nonexistent id (" + componentId + ") failed.");
     421                return Response.serverError().entity("Invalid id, cannot update nonexistent component").build();
     422            }
     423        } catch (ComponentRegistryException e) {
     424            LOG.info("Could not retrieve component", e);
     425            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     426        }
    365427    }
    366428
    367429    private void updateDescription(AbstractDescription desc, String name, String description, String domainName, String group) {
    368         desc.setName(name);
    369         desc.setDescription(description);
    370         desc.setDomainName(domainName);
    371         desc.setGroupName(group);
    372         desc.setRegistrationDate(AbstractDescription.createNewDate());
     430        desc.setName(name);
     431        desc.setDescription(description);
     432        desc.setDomainName(domainName);
     433        desc.setGroupName(group);
     434        desc.setRegistrationDate(AbstractDescription.createNewDate());
    373435    }
    374436
     
    376438    @Path("/components/{componentId}")
    377439    public Response deleteRegisteredComponent(@PathParam("componentId") String componentId,
    378             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    379         Principal principal = checkAndGetUserPrincipal();
    380         ComponentRegistry registry = getRegistry(userspace);
    381         LOG.info("Component with id: " + componentId + " set for deletion.");
    382         try {
    383             registry.deleteMDComponent(componentId, principal, false);
    384         } catch (DeleteFailedException e) {
    385             LOG.info("Component with id: " + componentId + " deletion failed.", e);
    386             return Response.status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
    387         } catch (ComponentRegistryException e) {
    388             LOG.info("Component with id: " + componentId + " deletion failed.", e);
    389             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    390         } catch (IOException e) {
    391             LOG.info("Component with id: " + componentId + " deletion failed.", e);
    392             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    393         } catch (UserUnauthorizedException e) {
    394             LOG.info("Component with id: " + componentId + " deletion failed: " + e.getMessage());
    395             return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    396         }
    397         LOG.info("Component with id: " + componentId + " deleted.");
    398         return Response.ok().build();
     440            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     441        Principal principal = checkAndGetUserPrincipal();
     442        ComponentRegistry registry = getRegistry(userspace);
     443        LOG.info("Component with id: " + componentId + " set for deletion.");
     444        try {
     445            registry.deleteMDComponent(componentId, principal, false);
     446        } catch (DeleteFailedException e) {
     447            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     448            return Response.status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     449        } catch (ComponentRegistryException e) {
     450            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     451            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     452        } catch (IOException e) {
     453            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     454            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     455        } catch (UserUnauthorizedException e) {
     456            LOG.info("Component with id: " + componentId + " deletion failed: " + e.getMessage());
     457            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     458        }
     459        LOG.info("Component with id: " + componentId + " deleted.");
     460        return Response.ok().build();
    399461    }
    400462
     
    402464    @Path("/profiles/{profileId}")
    403465    public Response deleteRegisteredProfile(@PathParam("profileId") String profileId,
    404             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    405         Principal principal = checkAndGetUserPrincipal();
    406         LOG.info("Profile with id: " + profileId + " set for deletion.");
    407         try {
    408             getRegistry(userspace).deleteMDProfile(profileId, principal);
    409         } catch (DeleteFailedException e) {
    410             LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
    411             return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
    412         } catch (ComponentRegistryException e) {
    413             LOG.info("Could not retrieve component", e);
    414             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    415         } catch (IOException e) {
    416             LOG.info("Profile with id: " + profileId + " deletion failed.", e);
    417             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    418         } catch (UserUnauthorizedException e) {
    419             LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
    420             return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    421         }
    422         LOG.info("Profile with id: " + profileId + " deleted.");
    423         return Response.ok().build();
    424     }
     466            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     467        Principal principal = checkAndGetUserPrincipal();
     468        LOG.info("Profile with id: " + profileId + " set for deletion.");
     469        try {
     470            getRegistry(userspace).deleteMDProfile(profileId, principal);
     471        } catch (DeleteFailedException e) {
     472            LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
     473            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     474        } catch (ComponentRegistryException e) {
     475            LOG.info("Could not retrieve component", e);
     476            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     477        } catch (IOException e) {
     478            LOG.info("Profile with id: " + profileId + " deletion failed.", e);
     479            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     480        } catch (UserUnauthorizedException e) {
     481            LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
     482            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     483        }
     484        LOG.info("Profile with id: " + profileId + " deleted.");
     485        return Response.ok().build();
     486    }
     487
     488//    @DELETE
     489//    @Path("/profiles/{profileId}/comments/{commentId}")
     490//    public Response deleteRegisteredCommentFromProfile(@PathParam("commentId") String commentId,
     491//            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     492//        Principal principal = checkAndGetUserPrincipal();
     493//        LOG.info("Comment with id: " + commentId + " set for deletion.");
     494//        try {
     495//            getRegistry(userspace).deleteMDComment(commentId, principal);
     496//        } catch (DeleteFailedException e) {
     497//            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     498//            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     499//        } catch (ComponentRegistryException e) {
     500//            LOG.info("Could not retrieve component", e);
     501//            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     502//        } catch (IOException e) {
     503//            LOG.info("Comment with id: " + commentId + " deletion failed.", e);
     504//            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     505//        } catch (UserUnauthorizedException e) {
     506//            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     507//            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     508//        }
     509//        LOG.info("Profile with id: " + commentId + " deleted.");
     510//        return Response.ok().build();
     511//    }
     512//
     513//    @DELETE
     514//    @Path("/components/{componentId}/comments/{commentId}")
     515//    public Response deleteRegisteredCommentFromComponent(@PathParam("commentId") String commentId,
     516//            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     517//        Principal principal = checkAndGetUserPrincipal();
     518//        LOG.info("Comment with id: " + commentId + " set for deletion.");
     519//        try {
     520//            getRegistry(userspace).deleteMDComment(commentId, principal);
     521//        } catch (DeleteFailedException e) {
     522//            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     523//            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     524//        } catch (ComponentRegistryException e) {
     525//            LOG.info("Could not retrieve component", e);
     526//            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     527//        } catch (IOException e) {
     528//            LOG.info("Comment with id: " + commentId + " deletion failed.", e);
     529//            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     530//        } catch (UserUnauthorizedException e) {
     531//            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     532//            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     533//        }
     534//        LOG.info("Profile with id: " + commentId + " deleted.");
     535//        return Response.ok().build();
     536//    }
    425537
    426538    @GET
     
    428540    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
    429541    public Response getRegisteredProfileRawType(@PathParam("profileId") final String profileId, @PathParam("rawType") String rawType) {
    430         LOG.info("Profile with id: " + profileId + " and rawType:" + rawType + " is requested.");
    431         StreamingOutput result = null;
    432         try {
    433             final ComponentRegistry registry = findRegistry(profileId, new ProfileClosure());
    434             if (registry == null) {
    435                 return Response.status(Status.NOT_FOUND).entity("Id: " + profileId + " is not registered, cannot create data.").build();
    436             }
    437             ProfileDescription desc = registry.getProfileDescription(profileId);
    438             checkAndThrowDescription(desc, profileId);
    439             String fileName = desc.getName() + "." + rawType;
    440 
    441             if ("xml".equalsIgnoreCase(rawType)) {
    442                 result = new StreamingOutput() {
    443 
    444                     @Override
    445                     public void write(OutputStream output) throws IOException, WebApplicationException {
    446                         try {
    447                             registry.getMDProfileAsXml(profileId, output);
    448                         } catch (ComponentRegistryException e) {
    449                             LOG.warn("Could not retrieve component", e);
    450                             throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    451                         }
    452                     }
    453                 };
    454             } else if ("xsd".equalsIgnoreCase(rawType)) {
    455                 result = new StreamingOutput() {
    456 
    457                     @Override
    458                     public void write(OutputStream output) throws IOException, WebApplicationException {
    459                         try {
    460                             registry.getMDProfileAsXsd(profileId, output);
    461                         } catch (ComponentRegistryException e) {
    462                             LOG.warn("Could not retrieve component", e);
    463                             throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    464                         }
    465                     }
    466                 };
    467             } else {
    468                 throw new WebApplicationException(Response.serverError().entity(
    469                         "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
    470             }
    471             return createDownloadResponse(result, fileName);
    472         } catch (ComponentRegistryException e) {
    473             LOG.info("Could not retrieve component", e);
    474             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    475         }
     542        LOG.info("Profile with id: " + profileId + " and rawType:" + rawType + " is requested.");
     543        StreamingOutput result = null;
     544        try {
     545            final ComponentRegistry registry = findRegistry(profileId, new ProfileClosure());
     546            if (registry == null) {
     547                return Response.status(Status.NOT_FOUND).entity("Id: " + profileId + " is not registered, cannot create data.").build();
     548            }
     549            ProfileDescription desc = registry.getProfileDescription(profileId);
     550            checkAndThrowDescription(desc, profileId);
     551            String fileName = desc.getName() + "." + rawType;
     552
     553            if ("xml".equalsIgnoreCase(rawType)) {
     554                result = new StreamingOutput() {
     555
     556                    @Override
     557                    public void write(OutputStream output) throws IOException, WebApplicationException {
     558                        try {
     559                            registry.getMDProfileAsXml(profileId, output);
     560                        } catch (ComponentRegistryException e) {
     561                            LOG.warn("Could not retrieve component", e);
     562                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     563                        }
     564                    }
     565                };
     566            } else if ("xsd".equalsIgnoreCase(rawType)) {
     567                result = new StreamingOutput() {
     568
     569                    @Override
     570                    public void write(OutputStream output) throws IOException, WebApplicationException {
     571                        try {
     572                            registry.getMDProfileAsXsd(profileId, output);
     573                        } catch (ComponentRegistryException e) {
     574                            LOG.warn("Could not retrieve component", e);
     575                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     576                        }
     577                    }
     578                };
     579            } else {
     580                throw new WebApplicationException(Response.serverError().entity(
     581                        "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
     582            }
     583            return createDownloadResponse(result, fileName);
     584        } catch (ComponentRegistryException e) {
     585            LOG.info("Could not retrieve component", e);
     586            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     587        }
    476588    }
    477589
    478590    private void checkAndThrowDescription(AbstractDescription desc, String id) {
    479         if (desc == null) {
    480             throw new WebApplicationException(Response.serverError().entity("Incorrect id:" + id + "cannot handle request").build());
    481         }
     591        if (desc == null) {
     592            throw new WebApplicationException(Response.serverError().entity("Incorrect id:" + id + "cannot handle request").build());
     593        }
    482594    }
    483595
    484596    private Response createDownloadResponse(StreamingOutput result, String fileName) {
    485         //Making response so it triggers browsers native save as dialog.
    486         Response response = Response.ok().type("application/x-download").header("Content-Disposition",
    487                 "attachment; filename=\"" + fileName + "\"").entity(result).build();
    488         return response;
     597        //Making response so it triggers browsers native save as dialog.
     598        Response response = Response.ok().type("application/x-download").header("Content-Disposition",
     599                "attachment; filename=\"" + fileName + "\"").entity(result).build();
     600        return response;
    489601
    490602    }
     
    495607    @Consumes("multipart/form-data")
    496608    public Response registerProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    497             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName,
    498             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    499         Principal principal = checkAndGetUserPrincipal();
    500         UserCredentials userCredentials = getUserCredentials(principal);
    501         ProfileDescription desc = createNewProfileDescription();
    502         desc.setCreatorName(userCredentials.getDisplayName());
    503         desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
    504         desc.setName(name);
    505         desc.setDescription(description);
    506         desc.setGroupName(group);
    507         desc.setDomainName(domainName);
    508         LOG.info("Trying to register Profile: " + desc);
    509         return register(input, desc, userCredentials, userspace, new NewAction());
     609            @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName,
     610            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     611        Principal principal = checkAndGetUserPrincipal();
     612        UserCredentials userCredentials = getUserCredentials(principal);
     613        ProfileDescription desc = createNewProfileDescription();
     614        desc.setCreatorName(userCredentials.getDisplayName());
     615        desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
     616        desc.setName(name);
     617        desc.setDescription(description);
     618        desc.setGroupName(group);
     619        desc.setDomainName(domainName);
     620        LOG.info("Trying to register Profile: " + desc);
     621        return register(input, desc, userCredentials, userspace, new NewAction());
    510622    }
    511623
     
    515627    @Consumes("multipart/form-data")
    516628    public Response registerComponent(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    517             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
    518             @FormDataParam(DOMAIN_FORM_FIELD) String domainName, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    519         Principal principal = checkAndGetUserPrincipal();
    520         UserCredentials userCredentials = getUserCredentials(principal);
    521         ComponentDescription desc = createNewComponentDescription();
    522         desc.setCreatorName(userCredentials.getDisplayName());
    523         desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
    524         desc.setName(name);
    525         desc.setDescription(description);
    526         desc.setGroupName(group);
    527         desc.setDomainName(domainName);
    528         LOG.info("Trying to register Component: " + desc);
    529         return register(input, desc, userCredentials, userspace, new NewAction());
     629            @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
     630            @FormDataParam(DOMAIN_FORM_FIELD) String domainName, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     631        Principal principal = checkAndGetUserPrincipal();
     632        UserCredentials userCredentials = getUserCredentials(principal);
     633        ComponentDescription desc = createNewComponentDescription();
     634        desc.setCreatorName(userCredentials.getDisplayName());
     635        desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
     636        desc.setName(name);
     637        desc.setDescription(description);
     638        desc.setGroupName(group);
     639        desc.setDomainName(domainName);
     640        LOG.info("Trying to register Component: " + desc);
     641        return register(input, desc, userCredentials, userspace, new NewAction());
    530642    }
    531643
     
    534646    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    535647    public Response pingSession() {
    536         boolean stillActive = false;
    537         Principal userPrincipal = security.getUserPrincipal();
    538         LOG.info("ping by user: " + (userPrincipal == null ? "null" : userPrincipal.getName()));
    539         if (request != null) {
    540             if (userPrincipal != null && !ComponentRegistryFactory.ANONYMOUS_USER.equals(userPrincipal.getName())) {
    541                 stillActive = !((HttpServletRequest) request).getSession().isNew();
    542             }
    543         }
    544         return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build();
     648        boolean stillActive = false;
     649        Principal userPrincipal = security.getUserPrincipal();
     650        LOG.info("ping by user: " + (userPrincipal == null ? "null" : userPrincipal.getName()));
     651        if (request != null) {
     652            if (userPrincipal != null && !ComponentRegistryFactory.ANONYMOUS_USER.equals(userPrincipal.getName())) {
     653                stillActive = !((HttpServletRequest) request).getSession().isNew();
     654            }
     655        }
     656        return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build();
    545657    }
    546658
    547659    private Response register(InputStream input, AbstractDescription desc, UserCredentials userCredentials, boolean userspace,
    548             RegisterAction action) {
    549         try {
    550             ComponentRegistry registry = getRegistry(userspace, userCredentials);
    551             DescriptionValidator descriptionValidator = new DescriptionValidator(desc);
    552             MDValidator validator = new MDValidator(input, desc, registry, getRegistry(true), componentRegistryFactory.getPublicRegistry());
    553             RegisterResponse response = new RegisterResponse();
    554             response.setIsInUserSpace(userspace);
    555             validate(response, descriptionValidator, validator);
    556             if (response.getErrors().isEmpty()) {
    557                 CMDComponentSpec spec = validator.getCMDComponentSpec();
    558                 int returnCode = action.execute(desc, spec, response, registry);
    559                 if (returnCode == 0) {
    560                     response.setRegistered(true);
    561                     response.setDescription(desc);
    562                 } else {
    563                     response.setRegistered(false);
    564                     response.addError("Unable to register at this moment. Internal server error.");
    565                 }
    566             } else {
    567                 LOG.info("Registration failed with validation errors:" + Arrays.toString(response.getErrors().toArray()));
    568                 response.setRegistered(false);
    569             }
    570             response.setIsProfile(desc.isProfile());
    571             return Response.ok(response).build();
    572         } finally {
    573             try {
    574                 input.close();//either we read the input or there was an exception, we need to close it.
    575             } catch (IOException e) {
    576                 LOG.error("Error when closing inputstream: ", e);
    577             }
    578         }
     660            RegisterAction action) {
     661        try {
     662            ComponentRegistry registry = getRegistry(userspace, userCredentials);
     663            DescriptionValidator descriptionValidator = new DescriptionValidator(desc);
     664            MDValidator validator = new MDValidator(input, desc, registry, getRegistry(true), componentRegistryFactory.getPublicRegistry());
     665            RegisterResponse response = new RegisterResponse();
     666            response.setIsInUserSpace(userspace);
     667            validate(response, descriptionValidator, validator);
     668            if (response.getErrors().isEmpty()) {
     669                CMDComponentSpec spec = validator.getCMDComponentSpec();
     670                int returnCode = action.execute(desc, spec, response, registry);
     671                if (returnCode == 0) {
     672                    response.setRegistered(true);
     673                    response.setDescription(desc);
     674                } else {
     675                    response.setRegistered(false);
     676                    response.addError("Unable to register at this moment. Internal server error.");
     677                }
     678            } else {
     679                LOG.info("Registration failed with validation errors:" + Arrays.toString(response.getErrors().toArray()));
     680                response.setRegistered(false);
     681            }
     682            response.setIsProfile(desc.isProfile());
     683            return Response.ok(response).build();
     684        } finally {
     685            try {
     686                input.close();//either we read the input or there was an exception, we need to close it.
     687            } catch (IOException e) {
     688                LOG.error("Error when closing inputstream: ", e);
     689            }
     690        }
    579691    }
    580692
    581693    private ComponentDescription createNewComponentDescription() {
    582         ComponentDescription desc = ComponentDescription.createNewDescription();
    583         desc.setHref(createXlink(desc.getId()));
    584         return desc;
     694        ComponentDescription desc = ComponentDescription.createNewDescription();
     695        desc.setHref(createXlink(desc.getId()));
     696        return desc;
    585697    }
    586698
    587699    private ProfileDescription createNewProfileDescription() {
    588         ProfileDescription desc = ProfileDescription.createNewDescription();
    589         desc.setHref(createXlink(desc.getId()));
    590         return desc;
     700        ProfileDescription desc = ProfileDescription.createNewDescription();
     701        desc.setHref(createXlink(desc.getId()));
     702        return desc;
    591703    }
    592704
    593705    private String createXlink(String id) {
    594         URI uri = uriInfo.getRequestUriBuilder().path(id).build();
    595         return uri.toString();
     706        URI uri = uriInfo.getRequestUriBuilder().path(id).build();
     707        return uri.toString();
    596708    }
    597709
    598710    private void validate(RegisterResponse response, Validator... validators) {
    599         for (Validator validator : validators) {
    600             if (!validator.validate()) {
    601                 for (String error : validator.getErrorMessages()) {
    602                     response.addError(error);
    603                 }
    604             }
    605         }
     711        for (Validator validator : validators) {
     712            if (!validator.validate()) {
     713                for (String error : validator.getErrorMessages()) {
     714                    response.addError(error);
     715                }
     716            }
     717        }
    606718    }
    607719
     
    610722     */
    611723    public void setComponentRegistryFactory(ComponentRegistryFactory componentRegistryFactory) {
    612         this.componentRegistryFactory = componentRegistryFactory;
     724        this.componentRegistryFactory = componentRegistryFactory;
    613725    }
    614726}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/sql/create.sql

    r1602 r1631  
    2020--
    2121
    22 CREATE TABLE comments (
    23     id SERIAL NOT NULL,
    24     profile_description_id integer,
    25     component_description_id integer,
    26     user_id integer,
    27     comments text NOT NULL
     22CREATE TABLE comments
     23(
     24  comment_id integer NOT NULL DEFAULT nextval('comments_id_seq'::regclass),
     25  comments text NOT NULL,
     26  comment_date timestamp with time zone,
     27  profile_description_id character varying,
     28  component_description_id character varying,
     29  user_id integer
     30
    2831);
    2932
     
    9396
    9497--
     98-- Name: comments_id_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
     99--
     100
     101ALTER TABLE ONLY comments
     102    ADD CONSTRAINT comments_id_pkey PRIMARY KEY(id);
     103
     104--
    95105-- Name: component_description_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
    96106--
     
    132142CREATE INDEX fki_comments_profile ON comments USING btree (profile_description_id);
    133143
     144--
     145-- Name: fki_comments_component; Type: INDEX; Schema: public; Owner: -; Tablespace:
     146--
     147
     148CREATE INDEX fki_comments_component ON comments USING btree (component_description_id);
     149
    134150
    135151--
     
    166182
    167183ALTER TABLE ONLY comments
    168     ADD CONSTRAINT comments_profile FOREIGN KEY (profile_description_id) REFERENCES profile_description(id);
     184    ADD CONSTRAINT comments_profile FOREIGN KEY (profile_description_id) REFERENCES profile_description(profile_id);
    169185
    170186
     
    175191ALTER TABLE ONLY comments
    176192    ADD CONSTRAINT comments_user FOREIGN KEY (user_id) REFERENCES registry_user(id);
     193
     194
     195--
     196-- Name: comments_component; Type: FK CONSTRAINT; Schema: public; Owner: -
     197--
     198
     199ALTER TABLE ONLY comments
     200    ADD CONSTRAINT comments_component FOREIGN KEY (component_description_id) REFERENCES component_description(component_id);
    177201
    178202
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/webresources/WEB-INF/spring-config/persistence.xml

    r1361 r1631  
    2020        <property name="dataSource" ref="dataSource"/>
    2121    </bean>
     22        <bean id="commentsDao" class="clarin.cmdi.componentregistry.impl.database.CommentsDao">
     23        <property name="dataSource" ref="dataSource"/>
     24    </bean>
    2225
    2326</beans>
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryTestDatabase.java

    r1603 r1631  
    2727                + "  description character varying NOT NULL,"
    2828                + "  registration_date timestamp,"// with timezone,"
    29                 + "  href character varying,"
     29                + "  href character varying,"
    3030                + "  creator_name character varying,"
    3131                + "  domain_name character varying,"
     
    4444                + "  description character varying NOT NULL,"
    4545                + "  registration_date timestamp,"// with timezone,"
    46                 + "  href character varying,"
     46                + "  href character varying,"
    4747                + "  creator_name character varying,"
    4848                + "  domain_name character varying,"
    4949                + "  group_name character varying, "
    50                 + "  show_in_editor boolean DEFAULT true NOT NULL, "
    51                 + "  CONSTRAINT UNIQUE_PROFILE_ID UNIQUE (profile_id));");
     50                + "  show_in_editor boolean DEFAULT true NOT NULL, "
     51                + "  CONSTRAINT UNIQUE_PROFILE_ID UNIQUE (profile_id));");
    5252    }
    5353
     
    6464    }
    6565
     66    public static void createTableComments(JdbcTemplate jdbcTemplate) {
     67        jdbcTemplate.execute("CREATE TABLE comments ("
     68                + "id IDENTITY NOT NULL,"
     69                + "user_id integer,"
     70                + "  profile_description_id character varying,"
     71                + "  component_description_id character varying,"               
     72                + "  comments character varying NOT NULL,"
     73                + "  comment_date timestamp,"
     74                + "  CONSTRAINT UNIQUE_COMMENTS_ID UNIQUE (id));");
     75    }
     76
    6677    public static void resetAndCreateAllTables(JdbcTemplate jdbcTemplate) {
    67         resetDatabase(jdbcTemplate);
    68         createTableComponentDescription(jdbcTemplate);
    69         createTableProfileDescription(jdbcTemplate);
    70         createTableXmlContent(jdbcTemplate);
    71         createTableRegistryUser(jdbcTemplate);
     78        resetDatabase(jdbcTemplate);
     79        createTableComponentDescription(jdbcTemplate);
     80        createTableProfileDescription(jdbcTemplate);
     81        createTableXmlContent(jdbcTemplate);
     82        createTableRegistryUser(jdbcTemplate);
     83        createTableComments(jdbcTemplate);
    7284    }
    7385}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/resources/spring-config/persistence.xml

    r1361 r1631  
    2020        <property name="dataSource" ref="dataSource"/>
    2121    </bean>
     22        <bean id="commentsDao" class="clarin.cmdi.componentregistry.impl.database.CommentsDao">
     23        <property name="dataSource" ref="dataSource"/>
     24    </bean>
    2225
    2326</beans>
  • ComponentRegistry/branches/jeaferversion/pom.xml

    r1568 r1631  
    2424    <ComponentRegistry.version>1.10.0-SNAPSHOT</ComponentRegistry.version>
    2525  </properties>
     26 
     27  <repositories>
     28<repository>
     29<id>cmdi.clarin.repository</id>
     30<name>Clarin Repository</name>
     31<url>http://catalog.clarin.eu/ds/nexus/content/groups/public/</url>
     32</repository>
     33 </repositories>
    2634
    2735  <reporting>
Note: See TracChangeset for help on using the changeset viewer.