Changeset 1364


Ignore:
Timestamp:
05/23/11 16:00:21 (13 years ago)
Author:
patdui
Message:
  • made admin pages work with db implementation. (undelete is still broken, will be fixed shortly).
Location:
ComponentRegistry/trunk/ComponentRegistry/src
Files:
1 deleted
22 edited
2 moved

Legend:

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

    r1357 r1364  
    3737     * @return -1 if component could not be updated
    3838     */
    39     int update(AbstractDescription description, CMDComponentSpec spec);
     39    int update(AbstractDescription description, CMDComponentSpec spec, Principal principal, boolean forceUpdate);
    4040
    4141    /**
     
    108108    List<ComponentDescription> getDeletedComponentDescriptions();
    109109
     110
    110111}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/AdminHomePage.html

    r1342 r1364  
    2121            </div>
    2222            <div class="infoView">
    23                 <form wicket:id="form">
    24                     <button wicket:id="delete">delete</button>
    25                     <button wicket:id="undelete">undelete</button>
    26                     <input type="checkbox" wicket:id="forceUpdate" />forceUpdate
    27                     <textarea  class="infoTextArea" wicket:id="text" >text</textarea>
    28                     <button wicket:id="submit">submit</button>
    29                 </form>
    3023                <div id="feedbackPanel">
    3124                    <span wicket:id="feedback"></span>
    3225                </div>
     26                <form wicket:id="form">
     27                    <button wicket:id="delete" title="Press delete button to delete this item">delete</button>
     28                    <button wicket:id="undelete" title="Press undelete button to put this item back in the registry">undelete</button>
     29                    <input type="checkbox" wicket:id="forceUpdate" />forceUpdate
     30                    <button wicket:id="submit">submit edit changes</button>
     31                    <textarea  class="descriptionTextArea" wicket:id="description" >text</textarea>
     32                    <textarea  class="contentTextArea" wicket:id="content" >text</textarea>
     33                </form>
    3334            </div>
    34         </div>
    35         <div class="treeView">
    36             <a wicket:id="expandAll">[expand all]</a>
    37             <a wicket:id="collapseAll">[collapse all]</a>
    38             <span wicket:id="tree2">tree2</span>
    3935        </div>
    4036    </body>
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/AdminHomePage.java

    r1352 r1364  
    11package clarin.cmdi.componentregistry.frontend;
    22
    3 import clarin.cmdi.componentregistry.ComponentRegistryException;
    4 import java.io.File;
    53import java.security.Principal;
    6 import java.util.ArrayList;
    74import java.util.List;
    85
     
    3027
    3128import clarin.cmdi.componentregistry.ComponentRegistry;
     29import clarin.cmdi.componentregistry.ComponentRegistryException;
    3230import clarin.cmdi.componentregistry.ComponentRegistryFactory;
     31import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao;
     32import clarin.cmdi.componentregistry.impl.database.ProfileDescriptionDao;
    3333import clarin.cmdi.componentregistry.impl.filesystem.AdminRegistry;
    34 import clarin.cmdi.componentregistry.impl.filesystem.FileSystemConfiguration;
    35 import clarin.cmdi.componentregistry.impl.filesystem.ResourceConfig;
    3634import clarin.cmdi.componentregistry.model.AbstractDescription;
     35import clarin.cmdi.componentregistry.model.ComponentDescription;
     36import clarin.cmdi.componentregistry.model.ProfileDescription;
    3737
    3838@SuppressWarnings("serial")
     
    4141    private final static Logger LOG = LoggerFactory.getLogger(AdminHomePage.class);
    4242
    43     private final FileInfo fileInfo = new FileInfo();
     43    private final CMDItemInfo info = new CMDItemInfo();
    4444    private final LinkTree tree;
    4545
    4646    private transient AdminRegistry adminRegistry = new AdminRegistry();
    4747
    48     @SpringBean(name="componentRegistryFactory")
     48    @SpringBean(name = "componentRegistryFactory")
    4949    private ComponentRegistryFactory componentRegistryFactory;
     50    @SpringBean
     51    private ProfileDescriptionDao profileDescriptionDao;
     52    @SpringBean
     53    private ComponentDescriptionDao componentDescriptionDao;
    5054
    5155    public AdminHomePage(final PageParameters parameters) throws ComponentRegistryException {
    52         super(parameters);
    53         addLinks();
    54         final FeedbackPanel feedback = new FeedbackPanel("feedback");
    55         feedback.setOutputMarkupId(true);
    56         add(feedback);
    57         Form form = new ItemEditForm("form");
    58         add(form);
    59 
    60         Button deleteButton = new AjaxFallbackButton("delete", form) {
    61             @Override
    62             protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
    63                 FileInfo fileInfo = (FileInfo) form.getModelObject();
    64                 info("deleting:" + fileInfo.getName());
    65                 Principal userPrincipal = getWebRequest().getHttpServletRequest().getUserPrincipal();
    66                 try {
    67                     adminRegistry.delete(fileInfo, userPrincipal);
    68                     tree.setModelObject(createTreeModel());
    69                     info("Item deleted.");
    70                 } catch (SubmitFailedException e) {
    71                     LOG.error("Admin: ", e);
    72                     error("Cannot delete: " + fileInfo.getName() + "\n error=" + e);
    73                 }
    74                 if (target != null) {
    75                     target.addComponent(form);
    76                     target.addComponent(tree);
    77                     target.addComponent(feedback);
    78                 }
    79             }
    80 
    81             public boolean isEnabled() {
    82                 return fileInfo.isDeletable();
    83             };
    84         };
    85         form.add(deleteButton);
    86 
    87         Button undeleteButton = new AjaxFallbackButton("undelete", form) {
    88             @Override
    89             protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
    90                 FileInfo fileInfo = (FileInfo) form.getModelObject();
    91                 info("undeleting:" + fileInfo.getName());
    92                 Principal userPrincipal = getWebRequest().getHttpServletRequest().getUserPrincipal();
    93                 try {
    94                     adminRegistry.undelete(fileInfo, userPrincipal);
    95                     info("Item put back.");
    96                     tree.setModelObject(createTreeModel());
    97                 } catch (SubmitFailedException e) {
    98                     LOG.error("Admin: ", e);
    99                     error("Cannot undelete: " + fileInfo.getName() + "\n error=" + e);
    100                 }
    101                 if (target != null) {
    102                     target.addComponent(form);
    103                     target.addComponent(tree);
    104                     target.addComponent(feedback);
    105                 }
    106             }
    107 
    108             public boolean isEnabled() {
    109                 return fileInfo.isUndeletable();
    110             }
    111 
    112         };
    113         form.add(undeleteButton);
    114 
    115         CheckBox forceUpdateCheck = new CheckBox("forceUpdate");
    116         form.add(forceUpdateCheck);
    117 
    118         Button submitButton = new AjaxFallbackButton("submit", form) {
    119             @Override
    120             protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
    121                 FileInfo fileInfo = (FileInfo) form.getModelObject();
    122                 Principal userPrincipal = getWebRequest().getHttpServletRequest().getUserPrincipal();
    123                 info("submitting:" + fileInfo.getName() + " id=(" + fileInfo.getDisplayNode().getId() + ")");
    124                 try {
    125                     adminRegistry.submitFile(fileInfo, userPrincipal);
    126                     info("submitting done.");
    127                 } catch (SubmitFailedException e) {
    128                     LOG.error("Admin: ", e);
    129                     error("Cannot submit: " + fileInfo.getName() + "\n error=" + e);
    130                 }
    131                 if (target != null) {
    132                     target.addComponent(form);
    133                     target.addComponent(feedback);
    134                 }
    135             }
    136 
    137             public boolean isEnabled() {
    138                 return fileInfo.isEditable();
    139             }
    140 
    141         };
    142         form.add(submitButton);
    143 
    144         tree = createTree("tree", form, createTreeModel());
    145         add(tree);
    146         add(new Link("expandAll") {
    147             @Override
    148             public void onClick() {
    149                 tree.getTreeState().expandAll();
    150             }
    151         });
    152 
    153         add(new Link("collapseAll") {
    154             @Override
    155             public void onClick() {
    156                 tree.getTreeState().collapseAll();
    157             }
    158         });
    159 
    160         LinkTree dbTree = createTree("tree2", form, createDBTreeModel());
    161         add(dbTree);
     56        super(parameters);
     57        adminRegistry.setComponentRegistryFactory(componentRegistryFactory);
     58        adminRegistry.setProfileDescriptionDao(profileDescriptionDao);
     59        adminRegistry.setComponentDescriptionDao(componentDescriptionDao);
     60        addLinks();
     61        final FeedbackPanel feedback = new FeedbackPanel("feedback");
     62        feedback.setOutputMarkupId(true);
     63        add(feedback);
     64        Form form = new ItemEditForm("form");
     65        add(form);
     66
     67        Button deleteButton = new AjaxFallbackButton("delete", form) {
     68            @Override
     69            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
     70                CMDItemInfo info = (CMDItemInfo) form.getModelObject();
     71                info("deleting:" + info.getName());
     72                Principal userPrincipal = getWebRequest().getHttpServletRequest().getUserPrincipal();
     73                try {
     74                    adminRegistry.delete(info, userPrincipal);
     75                    tree.setModelObject(createDBTreeModel());
     76                    info("Item deleted.");
     77                } catch (SubmitFailedException e) {
     78                    LOG.error("Admin: ", e);
     79                    error("Cannot delete: " + info.getName() + "\n error=" + e);
     80                } catch (ComponentRegistryException e) {
     81                    LOG.error("Admin: ", e);
     82                    error("Cannot delete: " + info.getName() + "\n error=" + e);
     83                }
     84                if (target != null) {
     85                    target.addComponent(form);
     86                    target.addComponent(tree);
     87                    target.addComponent(feedback);
     88                }
     89            }
     90
     91            public boolean isEnabled() {
     92                return info.isDeletable();
     93
     94            };
     95        };
     96        form.add(deleteButton);
     97
     98        Button undeleteButton = new AjaxFallbackButton("undelete", form) {
     99            @Override
     100            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
     101                CMDItemInfo info = (CMDItemInfo) form.getModelObject();
     102                info("undeleting:" + info.getName());
     103                try {
     104                    adminRegistry.undelete(info);
     105                    info("Item put back.");
     106                    tree.setModelObject(createDBTreeModel());
     107                } catch (SubmitFailedException e) {
     108                    LOG.error("Admin: ", e);
     109                    error("Cannot undelete: " + info.getName() + "\n error=" + e);
     110                } catch (ComponentRegistryException e) {
     111                    LOG.error("Admin: ", e);
     112                    error("Cannot undelete: " + info.getName() + "\n error=" + e);
     113                }
     114                if (target != null) {
     115                    target.addComponent(form);
     116                    target.addComponent(tree);
     117                    target.addComponent(feedback);
     118                }
     119            }
     120
     121            public boolean isEnabled() {
     122                return info.isUndeletable();
     123            }
     124
     125        };
     126        form.add(undeleteButton);
     127
     128        CheckBox forceUpdateCheck = new CheckBox("forceUpdate");
     129        form.add(forceUpdateCheck);
     130
     131        Button submitButton = new AjaxFallbackButton("submit", form) {
     132            @Override
     133            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
     134                CMDItemInfo info = (CMDItemInfo) form.getModelObject();
     135                Principal userPrincipal = getWebRequest().getHttpServletRequest().getUserPrincipal();
     136                info("submitting:" + info.getName() + " id=(" + info.getDataNode().getDescription().getId() + ")");
     137                try {
     138                    adminRegistry.submitFile(info, userPrincipal);
     139                    info("submitting done.");
     140                } catch (SubmitFailedException e) {
     141                    LOG.error("Admin: ", e);
     142                    error("Cannot submit: " + info.getName() + "\n error=" + e);
     143                }
     144                if (target != null) {
     145                    target.addComponent(form);
     146                    target.addComponent(feedback);
     147                }
     148            }
     149
     150            public boolean isEnabled() {
     151                return info.isEditable();
     152            }
     153
     154        };
     155        form.add(submitButton);
     156
     157        tree = createTree("tree", form, createDBTreeModel());
     158        add(tree);
     159        add(new Link("expandAll") {
     160            @Override
     161            public void onClick() {
     162                tree.getTreeState().expandAll();
     163            }
     164        });
     165
     166        add(new Link("collapseAll") {
     167            @Override
     168            public void onClick() {
     169                tree.getTreeState().collapseAll();
     170            }
     171        });
     172
    162173    }
    163174
    164175    private void addLinks() {
    165         add(new Label("linksMessage", "Browse the data below or choose on of the following options:"));
    166         add(new Link("massMigrate") {
    167             @Override
    168             public void onClick() {
    169                 setResponsePage(MassMigratePage.class);
    170             }
    171         });
    172         add(new Link("log") {
    173             @Override
    174             public void onClick() {
    175                 setResponsePage(ViewLogPage.class);
    176             }
    177         });
    178         add(new Link("statistics") {
    179             @Override
    180             public void onClick() {
    181                 setResponsePage(StatisticsPage.class);
    182             }
    183         });
     176        add(new Label("linksMessage", "Browse the data below or choose on of the following options:"));
     177        add(new Link("massMigrate") {
     178            @Override
     179            public void onClick() {
     180                setResponsePage(MassMigratePage.class);
     181            }
     182        });
     183        add(new Link("log") {
     184            @Override
     185            public void onClick() {
     186                setResponsePage(ViewLogPage.class);
     187            }
     188        });
     189        add(new Link("statistics") {
     190            @Override
     191            public void onClick() {
     192                setResponsePage(StatisticsPage.class);
     193            }
     194        });
    184195    }
    185196
    186197    private LinkTree createTree(String id, final Form form, TreeModel treeModel) {
    187         final LinkTree tree = new LinkTree(id, treeModel) {
    188             @Override
    189             protected void onNodeLinkClicked(Object node, BaseTree tree, AjaxRequestTarget target) {
    190                 super.onNodeLinkClicked(node, tree, target);
    191                 ITreeState treeState = tree.getTreeState();
    192                 if (treeState.isNodeExpanded(node)) {
    193                     treeState.collapseNode(node);
    194                 } else {
    195                     treeState.expandNode(node);
    196                 }
    197                 DisplayNode dn = (DisplayNode) ((DefaultMutableTreeNode) node).getUserObject();
    198                 fileInfo.setDisplayNode(dn);
    199                 if (target != null) {
    200                     target.addComponent(form);
    201                 }
    202             }
    203         };
    204         return tree;
    205     }
    206 
    207     private TreeModel createTreeModel() {
    208         File registryRoot = FileSystemConfiguration.getInstance().getRegistryRoot();
    209         TreeModel model = null;
    210         DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new FileNode(registryRoot, false));
    211         add(rootNode, registryRoot.listFiles(), false);
    212         model = new DefaultTreeModel(rootNode);
    213         return model;
    214     }
    215 
    216     @SuppressWarnings("unchecked")
    217     private void add(DefaultMutableTreeNode parent, File[] files, boolean isDeleted) {
    218         for (File file : files) {
    219             if (file.isDirectory()) {
    220                 boolean deleted = ResourceConfig.DELETED_DIR_NAME.equals(file.getName()) || isDeleted; //once you find a deleted dir mark all child nodes in the tree as deleted.
    221                 DefaultMutableTreeNode child = new DefaultMutableTreeNode(new FileNode(file, deleted));
    222                 parent.add(child);
    223                 add(child, file.listFiles(), deleted);
    224             } else {
    225                 DefaultMutableTreeNode child = new DefaultMutableTreeNode(new FileNode(file, isDeleted));
    226                 parent.add(child);
    227             }
    228         }
    229     }
    230 
    231     private class ItemEditForm extends Form<FileInfo> {
    232 
    233         public ItemEditForm(String name) {
    234             super(name);
    235             CompoundPropertyModel model = new CompoundPropertyModel(fileInfo);
    236             setModel(model);
    237 
    238             TextArea textArea = new TextArea("text");
    239             textArea.setOutputMarkupId(true);
    240             add(textArea);
    241         }
     198        final LinkTree tree = new LinkTree(id, treeModel) {
     199            @Override
     200            protected void onNodeLinkClicked(Object node, BaseTree tree, AjaxRequestTarget target) {
     201                super.onNodeLinkClicked(node, tree, target);
     202                ITreeState treeState = tree.getTreeState();
     203                if (treeState.isNodeExpanded(node)) {
     204                    treeState.collapseNode(node);
     205                } else {
     206                    treeState.expandNode(node);
     207                }
     208                DisplayDataNode dn = (DisplayDataNode) ((DefaultMutableTreeNode) node).getUserObject();
     209                info.setDataNode(dn);
     210                AbstractDescription desc = dn.getDescription();
     211                if (desc != null) {
     212                    String content;
     213                    if (desc.isProfile()) {
     214                        content = profileDescriptionDao.getContent(dn.isDeleted(), desc.getId());
     215                    } else {
     216                        content = componentDescriptionDao.getContent(dn.isDeleted(), desc.getId());
     217                    }
     218                    info.setContent(content);
     219                }
     220                if (target != null) {
     221                    target.addComponent(form);
     222                }
     223            }
     224        };
     225        return tree;
     226    }
     227
     228    private class ItemEditForm extends Form<CMDItemInfo> {
     229
     230        public ItemEditForm(String name) {
     231            super(name);
     232            CompoundPropertyModel model = new CompoundPropertyModel(info);
     233            setModel(model);
     234
     235            TextArea descriptionArea = new TextArea("description");
     236            descriptionArea.setOutputMarkupId(true);
     237            add(descriptionArea);
     238            TextArea contentArea = new TextArea("content");
     239            contentArea.setOutputMarkupId(true);
     240            add(contentArea);
     241        }
    242242
    243243    }
    244244
    245245    private TreeModel createDBTreeModel() throws ComponentRegistryException {
    246         DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new DisplayDataNode("ComponentRegistry", false));
    247         DefaultMutableTreeNode publicNode = new DefaultMutableTreeNode(new DisplayDataNode("Public", false));
    248         rootNode.add(publicNode);
    249         ComponentRegistry publicRegistry = componentRegistryFactory.getPublicRegistry();
    250         add(publicNode, publicRegistry);
    251         List<ComponentRegistry> userRegistries = componentRegistryFactory.getAllUserRegistries();
    252         int i = 0;
    253         for (ComponentRegistry registry : userRegistries) {
    254             DefaultMutableTreeNode userNode = new DefaultMutableTreeNode(new DisplayDataNode("user" + i++, false)); //TODO PD should have a registry.getName()
    255             rootNode.add(userNode);
    256             add(userNode, registry);
    257         }
    258         TreeModel model = new DefaultTreeModel(rootNode);
    259         return model;
     246        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new DisplayDataNode("ComponentRegistry", false));
     247        DefaultMutableTreeNode publicNode = new DefaultMutableTreeNode(new DisplayDataNode("Public", false));
     248        rootNode.add(publicNode);
     249        ComponentRegistry publicRegistry = componentRegistryFactory.getPublicRegistry();
     250        add(publicNode, publicRegistry);
     251        List<ComponentRegistry> userRegistries = componentRegistryFactory.getAllUserRegistries();
     252        for (ComponentRegistry registry : userRegistries) {
     253            DefaultMutableTreeNode userNode = new DefaultMutableTreeNode(new DisplayDataNode(registry.getName(), false));
     254            rootNode.add(userNode);
     255            add(userNode, registry);
     256        }
     257        TreeModel model = new DefaultTreeModel(rootNode);
     258        return model;
    260259    }
    261260
    262261    private void add(DefaultMutableTreeNode parent, ComponentRegistry registry) throws ComponentRegistryException {
    263         DefaultMutableTreeNode componentsNode = new DefaultMutableTreeNode(new DisplayDataNode("Components", false));
    264         parent.add(componentsNode);
    265         add(componentsNode, registry.getComponentDescriptions(), false);
    266 
    267         DefaultMutableTreeNode profilesNode = new DefaultMutableTreeNode(new DisplayDataNode("Profiles", false));
    268         parent.add(profilesNode);
    269         add(profilesNode, registry.getProfileDescriptions(), false);
    270 
    271         DefaultMutableTreeNode deletedCompNode = new DefaultMutableTreeNode(new DisplayDataNode("Deleted Components", true));
    272         parent.add(deletedCompNode);
    273         add(deletedCompNode, new ArrayList(), true); //TODO PD implement getDeletedComps/profiles
    274 
    275         DefaultMutableTreeNode deletedProfNode = new DefaultMutableTreeNode(new DisplayDataNode("Deleted Profiles", true));
    276         parent.add(deletedProfNode);
    277         add(deletedProfNode, new ArrayList(), true);
    278     }
    279 
    280     private void add(DefaultMutableTreeNode parent, List<? extends AbstractDescription> descs, boolean isDeleted) {
    281         for (AbstractDescription desc : descs) {
    282             DefaultMutableTreeNode child = new DefaultMutableTreeNode(new DisplayDataNode(desc.getName(), isDeleted));
    283             parent.add(child);
    284         }
     262        DefaultMutableTreeNode componentsNode = new DefaultMutableTreeNode(new DisplayDataNode("Components", false));
     263        parent.add(componentsNode);
     264        add(componentsNode, registry.getComponentDescriptions(), false, registry.isPublic());
     265
     266        DefaultMutableTreeNode profilesNode = new DefaultMutableTreeNode(new DisplayDataNode("Profiles", false));
     267        parent.add(profilesNode);
     268        add(profilesNode, registry.getProfileDescriptions(), false, registry.isPublic());
     269
     270        DefaultMutableTreeNode deletedCompNode = new DefaultMutableTreeNode(new DisplayDataNode("Deleted Components", true));
     271        parent.add(deletedCompNode);
     272
     273        List<ComponentDescription> deletedComponentDescriptions = registry.getDeletedComponentDescriptions();
     274        add(deletedCompNode, deletedComponentDescriptions, true, registry.isPublic());
     275
     276        DefaultMutableTreeNode deletedProfNode = new DefaultMutableTreeNode(new DisplayDataNode("Deleted Profiles", true));
     277        parent.add(deletedProfNode);
     278        List<ProfileDescription> deletedProfileDescriptions = registry.getDeletedProfileDescriptions();
     279        add(deletedProfNode, deletedProfileDescriptions, true, registry.isPublic());
     280    }
     281
     282    private void add(DefaultMutableTreeNode parent, List<? extends AbstractDescription> descs, boolean isDeleted, boolean isPublic) {
     283        for (AbstractDescription desc : descs) {
     284            DefaultMutableTreeNode child = new DefaultMutableTreeNode(new DisplayDataNode(desc.getName(), isDeleted, desc, isPublic));
     285            parent.add(child);
     286        }
    285287    }
    286288
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/CMDItemInfo.java

    r1342 r1364  
    33import java.io.Serializable;
    44
    5 public class FileInfo implements Serializable {
     5import clarin.cmdi.componentregistry.MDMarshaller;
     6import clarin.cmdi.componentregistry.model.AbstractDescription;
     7
     8public class CMDItemInfo implements Serializable {
    69
    710    private static final long serialVersionUID = 1L;
    811
    9     private String text;
     12    private String description;
     13    private String content;
    1014    private String name;
    1115    private boolean forceUpdate = false;
    1216
    13     private DisplayNode displayNode;
     17    private DisplayDataNode displayNode;
    1418
    1519    private boolean deletable = false;
     
    1822    private boolean editable = false;
    1923
    20     public void setText(String text) {
    21         this.text = text;
     24    public void setDescription(String descriptionText) {
     25        this.description = descriptionText;
    2226    }
    2327
    24     public String getText() {
    25         return text;
     28    public String getDescription() {
     29        return description;
    2630    }
    2731
     
    3741    }
    3842
    39     public DisplayNode getDisplayNode() {
     43    public DisplayDataNode getDataNode() {
    4044        return displayNode;
    4145    }
    4246
    43     public void setDisplayNode(DisplayNode displayNode) {
    44         this.displayNode = displayNode;
     47    public void setDataNode(DisplayDataNode dataNode) {
     48        this.displayNode = dataNode;
    4549        setUndeletable(false);
    4650        setDeletable(false);
    4751        setEditable(false);
    48         if (displayNode != null) {
    49             if (displayNode.hasContent()) {
    50                 setText(displayNode.getContent());
    51                 setEditable(displayNode.isEditable()); //file in root are not editable like:userMapping.xml
    52             } else {
    53                 //TODO PD have to test this
    54                 if (displayNode.isDeleted() && !displayNode.isEditable() && (displayNode.toString().startsWith("c_") || displayNode.toString().startsWith("p_"))) {
    55                     setText("Press undelete button to put this item back in the registry");
     52        setDescription("");
     53        setContent("");
     54        if (dataNode != null) {
     55            AbstractDescription desc = dataNode.getDescription();
     56            if (desc != null) {
     57                String content = MDMarshaller.marshalToString(desc);
     58                setDescription(content);
     59                setEditable(true);
     60                if (dataNode.isDeleted()) {
    5661                    setUndeletable(true);
    57                 } else if (!displayNode.isDeleted() && !displayNode.isEditable() && (displayNode.toString().startsWith("c_") || displayNode.toString().startsWith("p_"))) {
    58                     setText("Press delete button to delete this item");
     62                } else {
    5963                    setDeletable(true);
    60                 } else {
    61                     setText("");
    62                 }
     64                }
    6365            }
    6466        }
     
    9092    }
    9193
    92     public boolean isComponent() {
    93         return getName().startsWith("c_");
    94     }
    9594
    9695    public boolean isInUserWorkSpace() {
    97         return displayNode.isUserNode();
     96        return !displayNode.isPublic();
    9897    }
    9998
     
    106105    }
    107106
     107    public void setContent(String content) {
     108        this.content = content;
     109    }
     110
     111    public String getContent() {
     112        return content;
     113    }
     114
    108115}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/DisplayDataNode.java

    r1342 r1364  
    33import java.io.Serializable;
    44
    5 public class DisplayDataNode implements Serializable, DisplayNode {
     5import clarin.cmdi.componentregistry.model.AbstractDescription;
     6
     7public class DisplayDataNode implements Serializable {
    68
    79    private static final long serialVersionUID = 1L;
    810    private final String name;
    911    private final boolean isDeleted;
     12    private AbstractDescription desc;
     13    private final boolean isPublic;
    1014
    1115    public DisplayDataNode(String name, boolean isDeleted) {
     16        this(name, isDeleted, null, false);
     17    }
     18
     19    public DisplayDataNode(String name, boolean isDeleted, AbstractDescription desc, boolean isPublic) {
    1220        this.name = name;
    1321        this.isDeleted = isDeleted;
     22        this.desc = desc;
     23        this.isPublic = isPublic;
     24    }
     25
     26    /**
     27     * Can be null for non leaves.
     28     * @return
     29     */
     30    public AbstractDescription getDescription() {
     31        return desc;
     32    }
     33
     34    public boolean isDeleted() {
     35        return isDeleted;
    1436    }
    1537
     
    1941    }
    2042
    21     @Override
    22     public String getContent() {
    23         // TODO Auto-generated method stub
    24         return null;
     43    public boolean isPublic() {
     44        return isPublic;
    2545    }
    2646
    27     @Override
    28     public boolean hasContent() {
    29         // TODO Auto-generated method stub
    30         return false;
    31     }
    32 
    33     @Override
    34     public boolean isDeleted() {
    35         return isDeleted;
    36     }
    37 
    38     @Override
    39     public boolean isEditable() {
    40         // TODO Auto-generated method stub
    41         return false;
    42     }
    43 
    44     @Override
    45     public boolean isUserNode() {
    46         // TODO Auto-generated method stub
    47         return false;
    48     }
    49 
    50     @Override
    51     public String getId() {
    52         // TODO Auto-generated method stub
    53         return null;
    54     }
    5547}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/MassMigratePage.java

    r1352 r1364  
    11package clarin.cmdi.componentregistry.frontend;
    22
    3 import clarin.cmdi.componentregistry.ComponentRegistryException;
    4 import java.io.ByteArrayOutputStream;
    53import java.io.Serializable;
    6 import java.io.UnsupportedEncodingException;
    74import java.util.ArrayList;
    85import java.util.List;
    9 import java.util.logging.Level;
    10 
    11 import javax.xml.bind.JAXBException;
    126
    137import org.apache.wicket.Component;
     
    2519
    2620import clarin.cmdi.componentregistry.ComponentRegistry;
     21import clarin.cmdi.componentregistry.ComponentRegistryException;
    2722import clarin.cmdi.componentregistry.MDMarshaller;
    2823import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     
    127122                descDao.insertDescription(description, getContent(description, registry), registry.isPublic(), user.getId());
    128123            } catch (Exception e) {
    129                 LOG.error("Error in migration, check the logs!", e);
    130                 info("Error cannot migrate " + description.getId());
     124                LOG.error("Error in migration:", e);
     125                info("Error cannot migrate, check the logs!" + description.getId());
    131126            }
    132127            migrateCount++;
     
    135130    }
    136131
    137     private String getContent(AbstractDescription description, ComponentRegistry registry) throws UnsupportedEncodingException,
    138             JAXBException,
    139             ComponentRegistryException {
    140         ByteArrayOutputStream out = new ByteArrayOutputStream();
     132    private String getContent(AbstractDescription description, ComponentRegistry registry) throws ComponentRegistryException {
    141133        CMDComponentSpec spec = null;
    142134        if (description.isProfile()) {
     
    145137            spec = registry.getMDComponent(description.getId());
    146138        }
    147         MDMarshaller.marshal(spec, out);
    148         return out.toString();
     139        return MDMarshaller.marshalToString(spec);
    149140    }
    150141}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java

    r1352 r1364  
    11package clarin.cmdi.componentregistry.impl;
     2
     3import java.io.OutputStream;
     4import java.io.UnsupportedEncodingException;
     5import java.util.ArrayList;
     6import java.util.List;
     7
     8import javax.xml.bind.JAXBException;
     9
     10import org.apache.commons.lang.StringUtils;
     11import org.slf4j.Logger;
     12import org.slf4j.LoggerFactory;
    213
    314import clarin.cmdi.componentregistry.ComponentRegistry;
     
    516import clarin.cmdi.componentregistry.DeleteFailedException;
    617import clarin.cmdi.componentregistry.MDMarshaller;
    7 import clarin.cmdi.componentregistry.UserUnauthorizedException;
    818import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     19import clarin.cmdi.componentregistry.components.CMDComponentType;
    920import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header;
    10 import clarin.cmdi.componentregistry.components.CMDComponentType;
    1121import clarin.cmdi.componentregistry.model.AbstractDescription;
    1222import clarin.cmdi.componentregistry.model.ComponentDescription;
    1323import clarin.cmdi.componentregistry.model.ProfileDescription;
    14 import java.io.IOException;
    15 import java.io.OutputStream;
    16 import java.io.UnsupportedEncodingException;
    17 import java.security.Principal;
    18 import java.util.ArrayList;
    19 import java.util.List;
    20 import javax.xml.bind.JAXBException;
    21 import org.apache.commons.lang.StringUtils;
    22 import org.slf4j.Logger;
    23 import org.slf4j.LoggerFactory;
    2424
    2525/**
    26  *
     26 * 
    2727 * @author Twan Goosen <twan.goosen@mpi.nl>
    2828 */
     
    123123    }
    124124
    125     /* UNIMPLEMENTED INTERFACE METHODS */
    126     @Override
    127     public abstract List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException;
    128 
    129     @Override
    130     public abstract ComponentDescription getComponentDescription(String id) throws ComponentRegistryException;
    131 
    132     @Override
    133     public abstract List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException;
    134 
    135     @Override
    136     public abstract ProfileDescription getProfileDescription(String id) throws ComponentRegistryException;
    137 
    138     @Override
    139     public abstract CMDComponentSpec getMDProfile(String id) throws ComponentRegistryException;
    140 
    141     @Override
    142     public abstract CMDComponentSpec getMDComponent(String id) throws ComponentRegistryException;
    143 
    144     @Override
    145     public abstract int register(AbstractDescription desc, CMDComponentSpec spec);
    146 
    147     @Override
    148     public abstract int update(AbstractDescription description, CMDComponentSpec spec);
    149 
    150     @Override
    151     public abstract int publish(AbstractDescription desc, CMDComponentSpec spec, Principal principal);
    152 
    153     @Override
    154     public abstract void getMDProfileAsXml(String profileId, OutputStream output) throws ComponentRegistryException;
    155 
    156     @Override
    157     public abstract void getMDProfileAsXsd(String profileId, OutputStream outputStream) throws ComponentRegistryException;
    158 
    159     @Override
    160     public abstract void getMDComponentAsXml(String componentId, OutputStream output) throws ComponentRegistryException;
    161 
    162     @Override
    163     public abstract void getMDComponentAsXsd(String componentId, OutputStream outputStream) throws ComponentRegistryException;
    164 
    165     @Override
    166     public abstract void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException, DeleteFailedException, ComponentRegistryException;
    167 
    168     @Override
    169     public abstract void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException, DeleteFailedException, ComponentRegistryException;
    170 
    171     @Override
    172     public abstract boolean isPublic();
    173125}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/AbstractDescriptionDao.java

    r1362 r1364  
    5656     * @param cmdId
    5757     *            CMD id
    58      * @return Whether the specified item is in the public space, and not
    59      *         deleted or in a user's workspace
     58     * @return Whether the specified item is in the public space or in a user's workspace
    6059     */
    6160    public boolean isPublic(String cmdId) {
    6261        StringBuilder query = new StringBuilder("SELECT COUNT(*) FROM ");
    6362        query.append(getTableName());
    64         query.append(" WHERE is_deleted = false AND is_public = true AND ").append(getCMDIdColumn()).append(" = ?");
     63        query.append(" WHERE is_public = true AND ").append(getCMDIdColumn()).append(" = ?");
    6564        return (0 < getSimpleJdbcTemplate().queryForInt(query.toString(), cmdId));
    6665    }
     
    7271     * @param userId
    7372     *            User db id of workspace owner
    74      * @return Whether the specified item is in the specified user's workspace,
    75      *         and not deleted or the public space
     73     * @return Whether the specified item is in the specified user's workspace or the public space
    7674     */
    7775    public boolean isInUserSpace(String cmdId, Number userId) {
    7876        StringBuilder query = new StringBuilder("SELECT COUNT(*) FROM ");
    7977        query.append(getTableName());
    80         query.append(" WHERE is_deleted = false AND is_public = false AND user_id = ? AND ").append(getCMDIdColumn()).append(" = ?");
     78        query.append(" WHERE is_public = false AND user_id = ? AND ").append(getCMDIdColumn()).append(" = ?");
    8179        return (0 < getSimpleJdbcTemplate().queryForInt(query.toString(), userId, cmdId));
    8280    }
     
    8886     * @return String value of XML content for profile or component
    8987     */
    90     public String getContent(String cmdId) throws DataAccessException {
     88    public String getContent(boolean isDeleted, String cmdId) throws DataAccessException {
    9189        String select = "SELECT content FROM " + TABLE_XML_CONTENT + " JOIN " + getTableName() + " ON " + TABLE_XML_CONTENT + "."
    92                 + COLUMN_ID + " = " + getTableName() + ".content_id" + " WHERE is_deleted = false AND " + getTableName() + "."
     90                + COLUMN_ID + " = " + getTableName() + ".content_id" + " WHERE is_deleted = ? AND " + getTableName() + "."
    9391                + getCMDIdColumn() + " = ?";
    9492
    95         List<String> result = getSimpleJdbcTemplate().query(select, new ParameterizedSingleColumnRowMapper<String>(), cmdId);
     93        List<String> result = getSimpleJdbcTemplate().query(select, new ParameterizedSingleColumnRowMapper<String>(), isDeleted, cmdId);
    9694        if (result.size() > 0) {
    9795            return result.get(0);
     
    262260     * @param userId
    263261     */
    264     public List<T> getDeletedDescriptions(Number userId) {//TODO PD make test!
     262    public List<T> getDeletedDescriptions(Number userId) {
    265263        if (userId != null) {
    266264            String select = getSelectStatement().append(" WHERE is_deleted = true AND is_public = false AND user_id = ?").toString();
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r1359 r1364  
    217217
    218218    @Override
    219     public int update(AbstractDescription description, CMDComponentSpec spec) {
    220         try {
     219    public int update(AbstractDescription description, CMDComponentSpec spec, Principal principal, boolean forceUpdate) {
     220        try {
     221            checkAuthorisation(description, principal);
     222            checkAge(description, principal);
     223            if (!forceUpdate && !description.isProfile()) {
     224                checkStillUsed(description.getId());
     225            }
    221226            AbstractDescriptionDao<?> dao = getDaoForDescription(description);
    222227            dao.updateDescription(getIdForDescription(description), description, componentSpecToString(spec));
    223228            invalidateCache(description);
    224229            return 0;
    225         } catch (DataAccessException ex) {
    226             LOG.error("Database error while updating component", ex);
    227             return -1;
    228230        } catch (JAXBException ex) {
    229231            LOG.error("Error while updating component", ex);
    230             return -2;
     232            return -1;
    231233        } catch (UnsupportedEncodingException ex) {
    232234            LOG.error("Error while updating component", ex);
    233             return -3;
     235            return -1;
    234236        } catch (IllegalArgumentException ex) {
    235237            LOG.error("Error while updating component", ex);
    236             return -4;
     238            return -1;
     239        } catch (UserUnauthorizedException e) {
     240            LOG.error("Error while updating component", e);
     241            return -1;
     242        } catch (DeleteFailedException e) {
     243            LOG.error("Error while updating component", e);
     244            return -1;
     245        } catch (ComponentRegistryException e) {
     246            LOG.error("Error while updating component", e);
     247            return -1;
    237248        }
    238249    }
     
    242253        int result = 0;
    243254        AbstractDescriptionDao<?> dao = getDaoForDescription(desc);
    244         if (!isPublic()) { // if already in public workspace there is nothing
    245             // todo
     255        if (!isPublic()) { // if already in public workspace there is nothing todo
    246256            desc.setHref(AbstractDescription.createPublicHref(desc.getHref()));
    247257            Number id = getIdForDescription(desc);
     
    395405
    396406    private CMDComponentSpec getUncachedMDComponent(String id, AbstractDescriptionDao dao) {
    397         String xml = dao.getContent(id);
     407        String xml = dao.getContent(false, id);
    398408        if (xml != null) {
    399409            try {
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/filesystem/AdminRegistry.java

    r1352 r1364  
    11package clarin.cmdi.componentregistry.impl.filesystem;
    22
    3 import clarin.cmdi.componentregistry.ComponentRegistryException;
    4 import java.io.File;
    5 import java.io.FileInputStream;
    6 import java.io.FileNotFoundException;
    73import java.io.IOException;
    84import java.security.Principal;
     
    106import javax.xml.bind.JAXBException;
    117
    12 import org.apache.commons.io.FileUtils;
    138import org.apache.commons.io.IOUtils;
    149import org.slf4j.Logger;
    1510import org.slf4j.LoggerFactory;
     11import org.springframework.dao.DataAccessException;
    1612
    1713import clarin.cmdi.componentregistry.ComponentRegistry;
     14import clarin.cmdi.componentregistry.ComponentRegistryException;
     15import clarin.cmdi.componentregistry.ComponentRegistryFactory;
    1816import clarin.cmdi.componentregistry.DeleteFailedException;
    1917import clarin.cmdi.componentregistry.MDMarshaller;
    2018import clarin.cmdi.componentregistry.UserUnauthorizedException;
    2119import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    22 import clarin.cmdi.componentregistry.frontend.FileInfo;
    23 import clarin.cmdi.componentregistry.frontend.FileNode;
     20import clarin.cmdi.componentregistry.frontend.CMDItemInfo;
    2421import clarin.cmdi.componentregistry.frontend.SubmitFailedException;
     22import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao;
     23import clarin.cmdi.componentregistry.impl.database.ProfileDescriptionDao;
    2524import clarin.cmdi.componentregistry.model.AbstractDescription;
    2625import clarin.cmdi.componentregistry.model.ComponentDescription;
     
    2827
    2928public class AdminRegistry {
    30 
    3129    private final static Logger LOG = LoggerFactory.getLogger(AdminRegistry.class);
    3230
    33     public void submitFile(FileInfo fileInfo, Principal userPrincipal) throws SubmitFailedException {
     31    private ComponentRegistryFactory componentRegistryFactory;
     32    private ProfileDescriptionDao profileDescriptionDao;
     33    private ComponentDescriptionDao componentDescriptionDao;
     34
     35    public void setComponentRegistryFactory(ComponentRegistryFactory componentRegistryFactory) {
     36        this.componentRegistryFactory = componentRegistryFactory;
     37    }
     38
     39    public void setProfileDescriptionDao(ProfileDescriptionDao profileDescriptionDao) {
     40        this.profileDescriptionDao = profileDescriptionDao;
     41    }
     42
     43    public void setComponentDescriptionDao(ComponentDescriptionDao componentDescriptionDao) {
     44        this.componentDescriptionDao = componentDescriptionDao;
     45    }
     46
     47    public void submitFile(CMDItemInfo info, Principal userPrincipal) throws SubmitFailedException {
    3448        try {
    35             File file = getFile(fileInfo);
    36             if (fileInfo.getDisplayNode().isDeleted()) {
    37                 //already deleted file
    38                 FileUtils.writeStringToFile(file, fileInfo.getText(), "UTF-8");
     49            AbstractDescription originalDescription = info.getDataNode().getDescription();
     50            AbstractDescription description = null;
     51            CMDComponentSpec spec = null;
     52            if (originalDescription.isProfile()) {
     53                description = MDMarshaller.unmarshal(ProfileDescription.class, IOUtils.toInputStream(info.getDescription(), "UTF-8"), null);
    3954            } else {
    40                 //Description or cmdSpec file.
    41                 String name = fileInfo.getName();
    42                 String id = ComponentRegistry.REGISTRY_ID + getFile(fileInfo).getParentFile().getName();
    43                 AbstractDescription originalDescription = getDescription(fileInfo);
    44                 CMDComponentSpec originalSpec = getSpec(fileInfo);
    45                 AbstractDescription description = null;
    46                 CMDComponentSpec spec = null;
    47                 if (ComponentRegistryImpl.DESCRIPTION_FILE_NAME.equals(name)) {
    48                     if (getFile(fileInfo).getParentFile().getName().startsWith("c_")) {
    49                         description = MDMarshaller.unmarshal(ComponentDescription.class,
    50                                 IOUtils.toInputStream(fileInfo.getText(), "UTF-8"), null);
    51                     } else {
    52                         description = MDMarshaller.unmarshal(ProfileDescription.class, IOUtils.toInputStream(fileInfo.getText(), "UTF-8"),
    53                                 null);
    54                     }
    55                     checkId(id, description.getId());
    56                     spec = originalSpec;
    57                 } else {
    58                     spec = MDMarshaller.unmarshal(CMDComponentSpec.class, IOUtils.toInputStream(fileInfo.getText(), "UTF-8"), MDMarshaller.getCMDComponentSchema());
    59                     checkId(id, spec.getHeader().getID());
    60                     description = originalDescription;
    61                 }
    62                 deleteFromRegistry(userPrincipal, originalDescription, fileInfo);
    63                 int result = submitToRegistry(description, spec, userPrincipal, fileInfo);
    64                 if (result == 0) {
    65                     //submit is successful so now really delete the old one, we cannot have that around anymore.
    66                     ComponentRegistryImpl registry = (ComponentRegistryImpl) getRegistry(userPrincipal, originalDescription, fileInfo);
    67                     registry.emptyFromTrashcan(originalDescription);
    68                 } else {
    69                     throw new SubmitFailedException("Problem occured while registering, please check the tomcat logs for errors. "
    70                             + "Original files are removed already you can find them "
    71                             + "in the deleted section of the registry. You have to put that back manually.");
    72                 }
     55                description = MDMarshaller.unmarshal(ComponentDescription.class, IOUtils.toInputStream(info.getDescription(), "UTF-8"),
     56                        null);
     57            }
     58            spec = MDMarshaller.unmarshal(CMDComponentSpec.class, IOUtils.toInputStream(info.getContent(), "UTF-8"), null);
     59            checkId(originalDescription.getId(), description.getId());
     60
     61            int result = getRegistry(userPrincipal, originalDescription, info).update(description, spec, userPrincipal, info.isForceUpdate());
     62            if (result < 0) {
     63                throw new SubmitFailedException("Problem occured while registering, please check the tomcat logs for errors.");
    7364            }
    7465        } catch (JAXBException e) {
     
    7667        } catch (IOException e) {
    7768            throw new SubmitFailedException(e);
    78         } catch (UserUnauthorizedException e) {
    79             throw new SubmitFailedException(e);
    80         } catch (DeleteFailedException e) {
    81             throw new SubmitFailedException(e);
    82         } catch (ComponentRegistryException e) {
    83             throw new SubmitFailedException(e);
    8469        }
    85 
    8670    }
    8771
     
    9276    }
    9377
    94     public void undelete(FileInfo fileInfo, Principal userPrincipal) throws SubmitFailedException {
    95         String id = fileInfo.getName();
    96         AbstractDescription desc = getDescription(fileInfo);
     78    public void undelete(CMDItemInfo info) throws SubmitFailedException {
     79        AbstractDescription desc = info.getDataNode().getDescription();
    9780        try {
    98             CMDComponentSpec spec = getSpec(fileInfo);
    99             int result = submitToRegistry(desc, spec, userPrincipal, fileInfo);
    100             if (result == 0) {
    101                 FileUtils.deleteDirectory(getFile(fileInfo));
    102                 LOG.info("Undeleted item: " + id);
     81            if (desc.isProfile()) {
     82                profileDescriptionDao.setDeleted(desc, false);
    10383            } else {
    104                 throw new SubmitFailedException("Problem occured while registering, please check the tomcat logs for errors.");
     84                componentDescriptionDao.setDeleted(desc, false);
    10585            }
    106         } catch (IOException e) {
    107             throw new SubmitFailedException(e);
    108         } catch (JAXBException e) {
    109             throw new SubmitFailedException(e);
     86        } catch (DataAccessException e) {
     87            throw new SubmitFailedException("Undelete failed", e);
    11088        }
    111 
    11289    }
    11390
    114     public void delete(FileInfo fileInfo, Principal userPrincipal) throws SubmitFailedException {
    115         String id = fileInfo.getName();
    116         AbstractDescription desc = getDescription(fileInfo);
     91    public void delete(CMDItemInfo info, Principal userPrincipal) throws SubmitFailedException {
     92        String id = info.getName();
     93        AbstractDescription desc = info.getDataNode().getDescription();
    11794        try {
    118             deleteFromRegistry(userPrincipal, desc, fileInfo);
     95            deleteFromRegistry(userPrincipal, desc, info);
    11996            LOG.info("Deleted item: " + id);
    12097        } catch (IOException e) {
     
    130107    }
    131108
    132     private int submitToRegistry(AbstractDescription description, CMDComponentSpec spec, Principal userPrincipal, FileInfo fileInfo) {
    133         ComponentRegistry registry = getRegistry(userPrincipal, description, fileInfo);
    134         if (spec.isIsProfile()) {
    135             return registry.register((ProfileDescription) description, spec);
    136         } else {
    137             return registry.register((ComponentDescription) description, spec);
    138         }
    139 
    140     }
    141 
    142     private void deleteFromRegistry(Principal userPrincipal, AbstractDescription desc, FileInfo fileInfo) throws IOException,
    143             UserUnauthorizedException, DeleteFailedException, ComponentRegistryException {
    144         ComponentRegistry registry = getRegistry(userPrincipal, desc, fileInfo);
     109    private void deleteFromRegistry(Principal userPrincipal, AbstractDescription desc, CMDItemInfo info) throws IOException,
     110            UserUnauthorizedException, ComponentRegistryException {
     111        ComponentRegistry registry = getRegistry(userPrincipal, desc, info);
    145112        LOG.info("Deleting item: " + desc);
    146113        if (desc.isProfile()) {
    147114            registry.deleteMDProfile(desc.getId(), userPrincipal);
    148115        } else {
    149             registry.deleteMDComponent(desc.getId(), userPrincipal, fileInfo.isForceUpdate());
     116            registry.deleteMDComponent(desc.getId(), userPrincipal, info.isForceUpdate());
    150117        }
    151118    }
    152119
    153     private ComponentRegistry getRegistry(Principal userPrincipal, AbstractDescription desc, FileInfo fileInfo) {
    154         ComponentRegistry registry = ComponentRegistryFactoryImpl.getInstance().getPublicRegistry();
    155         if (fileInfo.isInUserWorkSpace()) {
    156             registry = ComponentRegistryFactoryImpl.getInstance().getOtherUserComponentRegistry(userPrincipal, desc.getUserId());
     120    private ComponentRegistry getRegistry(Principal userPrincipal, AbstractDescription desc, CMDItemInfo info) {
     121        ComponentRegistry registry = componentRegistryFactory.getPublicRegistry();
     122        if (info.isInUserWorkSpace()) {
     123            registry = componentRegistryFactory.getOtherUserComponentRegistry(userPrincipal, desc.getUserId());
    157124        }
    158125        return registry;
    159126    }
    160127
    161     private CMDComponentSpec getSpec(FileInfo fileInfo) throws FileNotFoundException, JAXBException {
    162         File parent = getFile(fileInfo);
    163         if (!parent.isDirectory()) {
    164             parent = parent.getParentFile();
    165         }
    166         File file = new File(parent, parent.getName() + ".xml");
    167         CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, new FileInputStream(file), MDMarshaller.getCMDComponentSchema());
    168         return spec;
    169     }
    170 
    171     private AbstractDescription getDescription(FileInfo fileInfo) {
    172         File parent = getFile(fileInfo);
    173         if (!parent.isDirectory()) {
    174             parent = parent.getParentFile();
    175         }
    176         File descFile = new File(parent, ComponentRegistryImpl.DESCRIPTION_FILE_NAME);
    177         Class<? extends AbstractDescription> clazz = fileInfo.isComponent() ? ComponentDescription.class : ProfileDescription.class;
    178         AbstractDescription result = MDMarshaller.unmarshal(clazz, descFile, null);
    179         return result;
    180     }
    181 
    182     private File getFile(FileInfo fileInfo) {
    183         FileNode fileNode = (FileNode) fileInfo.getDisplayNode();
    184         return fileNode.getFile();
    185     }
    186128}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryImpl.java

    r1359 r1364  
    275275
    276276    @Override
    277     public int update(AbstractDescription desc, CMDComponentSpec spec) {
     277    public int update(AbstractDescription desc, CMDComponentSpec spec, Principal principal, boolean forceUpdate) {
    278278        LOG.info("Attempt to update " + desc.getType() + ": " + desc);
    279279        return register(getDir(desc), desc, spec, new UpdateClosureOnFail(desc));
     
    468468        throw new NotImplementedException();
    469469    }
     470
    470471}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1352 r1364  
    255255            if (desc != null) {
    256256                updateDescription(desc, name, description, domainName, group);
    257                 return register(input, desc, userCredentials, userspace, new UpdateAction());
     257                return register(input, desc, userCredentials, userspace, new UpdateAction(principal));
    258258            } else {
    259259                LOG.error("Update of nonexistent id (" + profileId + ") failed.");
     
    320320            if (desc != null) {
    321321                updateDescription(desc, name, description, domainName, group);
    322                 return register(input, desc, getUserCredentials(principal), userspace, new UpdateAction());
     322                return register(input, desc, getUserCredentials(principal), userspace, new UpdateAction(principal));
    323323            } else {
    324324                LOG.error("Update of nonexistent id (" + componentId + ") failed.");
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/UpdateAction.java

    r1087 r1364  
    11package clarin.cmdi.componentregistry.rest;
     2
     3import java.security.Principal;
    24
    35import clarin.cmdi.componentregistry.ComponentRegistry;
     
    79
    810public class UpdateAction implements RegisterAction {
     11   
     12    private final Principal principal;
    913
     14    public UpdateAction(Principal principal) {
     15        this.principal = principal;
     16    }
     17   
    1018    @Override
    1119    public int execute(AbstractDescription desc, CMDComponentSpec spec, RegisterResponse response, ComponentRegistry registry) {
    12         return registry.update(desc, spec);
     20        return registry.update(desc, spec, principal, false);
    1321    }
    1422
  • ComponentRegistry/trunk/ComponentRegistry/src/main/webapp/css/adminstyle.css

    r622 r1364  
    1616}
    1717
    18 textArea.infoTextArea {
     18textArea.contentTextArea {
    1919           width: 100%;
    2020           height: 500px;
    2121}
     22
     23textArea.descriptionTextArea {
     24       width: 100%;
     25       height: 200px;
     26}
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/frontend/CMDItemInfoTest.java

    r1342 r1364  
    11package clarin.cmdi.componentregistry.frontend;
    22
     3import static org.junit.Assert.assertEquals;
    34import static org.junit.Assert.assertFalse;
    45import static org.junit.Assert.assertTrue;
    56
    6 import java.io.File;
    7 import java.io.IOException;
    8 
    9 import org.apache.commons.io.FileUtils;
    10 import org.junit.After;
    117import org.junit.Test;
    128
    13 import clarin.cmdi.componentregistry.impl.filesystem.ComponentRegistryTestCase;
    14 import clarin.cmdi.componentregistry.impl.filesystem.FileSystemConfiguration;
     9import clarin.cmdi.componentregistry.model.AbstractDescription;
     10import clarin.cmdi.componentregistry.model.ProfileDescription;
    1511
    16 public class FileInfoTest {
    17 
    18     private File rootDir;
     12public class CMDItemInfoTest {
    1913
    2014    @Test
    2115    public void testGetUserDir() throws Exception {
    22         rootDir = ComponentRegistryTestCase.createTempRegistryDir();
    23         FileSystemConfiguration.getInstance().setRegistryRoot(rootDir);
    24         FileInfo info = new FileInfo();
    25         info.setDisplayNode(new FileNode(createFile("users/user1/components/c_123/description.xml"), false));
    26         assertFalse(info.isDeletable());
     16        CMDItemInfo info = new CMDItemInfo();
     17        //info.setDataNode(new FileNode(createFile("users/user1/components/c_123/description.xml"), false));
     18        info.setDataNode(new DisplayDataNode("test", false, createDescription(), false));
     19        assertTrue(info.isDeletable());
    2720        assertFalse(info.isUndeletable());
    2821        assertTrue(info.isEditable());
    29         assertFalse(info.getDisplayNode().isDeleted());
     22        assertFalse(info.getDataNode().isDeleted());
    3023        assertTrue(info.isInUserWorkSpace());
    31         info.setDisplayNode(new FileNode(createFile("users/user1/components/deleted/c_123/description.xml"), true));
     24        //info.setDataNode(new FileNode(createFile("users/user1/components/deleted/c_123/description.xml"), true));
     25        info.setDataNode(new DisplayDataNode("test", true, createDescription(), false));
    3226        assertFalse(info.isDeletable());
    33         assertFalse(info.isUndeletable());
     27        assertTrue(info.isUndeletable());
    3428        assertTrue(info.isEditable());
    35         assertTrue(info.getDisplayNode().isDeleted());
     29        assertTrue(info.getDataNode().isDeleted());
    3630        assertTrue(info.isInUserWorkSpace());
    37         info.setDisplayNode(new FileNode(createFile("components/c_123/description.xml"), false));
    38         assertFalse(info.isDeletable());
     31        //info.setDataNode(new FileNode(createFile("components/c_123/description.xml"), false));
     32        info.setDataNode(new DisplayDataNode("test", false, createDescription(), true));
     33        assertTrue(info.isDeletable());
    3934        assertFalse(info.isUndeletable());
    4035        assertTrue(info.isEditable());
    4136        assertFalse(info.isInUserWorkSpace());
    42         info.setDisplayNode(new FileNode(createFile("components/c_123/"), false));
    43         assertTrue(info.isDeletable());
    44         assertFalse(info.isUndeletable());
    45         assertFalse(info.isEditable());
    46         assertFalse(info.isInUserWorkSpace());
    47         info.setDisplayNode(new FileNode(createFile("components/deleted/c_123/description.xml"), true));
    48         assertFalse(info.isDeletable());
    49         assertFalse(info.isUndeletable());
    50         assertTrue(info.isEditable());
    51         assertFalse(info.isInUserWorkSpace());
    52         info.setDisplayNode(new FileNode(createFile("components/deleted/c_123/"), true));
    53         assertFalse(info.isDeletable());
    54         assertTrue(info.isUndeletable());
    55         assertFalse(info.isEditable());
    56         assertFalse(info.isInUserWorkSpace());
    57         info.setDisplayNode(new FileNode(createFile("components/deleted/"), true));
     37        //info.setDataNode(new FileNode(createFile("components/c_123/"), false));
     38        info.setDataNode(new DisplayDataNode("test", false));
    5839        assertFalse(info.isDeletable());
    5940        assertFalse(info.isUndeletable());
    6041        assertFalse(info.isEditable());
     42        //info.setDataNode(new FileNode(createFile("components/deleted/c_123/description.xml"), true));
     43        info.setDataNode(new DisplayDataNode("test", true, createDescription(), true));
     44        assertFalse(info.isDeletable());
     45        assertTrue(info.isUndeletable());
     46        assertTrue(info.isEditable());
    6147        assertFalse(info.isInUserWorkSpace());
    62         info.setDisplayNode(new FileNode(createFile("/"), false));
     48        assertTrue(info.getDescription().startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<profileDescription"));
     49        //info.setDataNode(new FileNode(createFile("components/deleted/c_123/"), true));
     50        info.setDataNode(new DisplayDataNode("test", true));
    6351        assertFalse(info.isDeletable());
    6452        assertFalse(info.isUndeletable());
    6553        assertFalse(info.isEditable());
    66         assertFalse(info.isInUserWorkSpace());
    67         info.setDisplayNode(new FileNode(createFile("/userMapping.xml"), false));
    68         assertFalse(info.isDeletable());
    69         assertFalse(info.isUndeletable());
    70         assertFalse(info.isEditable());
    71         assertFalse(info.isInUserWorkSpace());
    72         info.setDisplayNode(new FileNode(createFile("users/"), false));
    73         assertFalse(info.isDeletable());
    74         assertFalse(info.isUndeletable());
    75         assertFalse(info.isEditable());
    76         assertTrue(info.isInUserWorkSpace());
    77         info.setDisplayNode(new FileNode(createFile("users/user1/components/c_123/"), false));
    78         assertTrue(info.isDeletable());
    79         assertFalse(info.isUndeletable());
    80         assertFalse(info.isEditable());
    81         assertTrue(info.isInUserWorkSpace());
    82         info.setDisplayNode(new FileNode(createFile("users/user1/components/deleted/c_123/"), true));
    83         assertFalse(info.isDeletable());
    84         assertTrue(info.isUndeletable());
    85         assertFalse(info.isEditable());
    86         assertTrue(info.isInUserWorkSpace());
     54        assertEquals("", info.getDescription());
    8755    }
    8856
    89     private File createFile(String fileName) throws IOException {
    90         File file = new File(rootDir, fileName);
    91         if (fileName.endsWith("/")) {
    92             file.mkdirs();
    93         } else {
    94             FileUtils.writeStringToFile(file, "");
    95         }
    96         return file;
    97     }
    98 
    99     @After
    100     public void cleanup() throws IOException {
    101         if (rootDir != null && rootDir.exists()) {
    102             FileUtils.deleteDirectory(rootDir);
    103         }
     57    private AbstractDescription createDescription() {
     58        return ProfileDescription.createNewDescription();
    10459    }
    10560
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AbstractDescriptionDaoTest.java

    r1358 r1364  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertFalse;
    45import static org.junit.Assert.assertNotNull;
     6import static org.junit.Assert.assertTrue;
    57
    68import java.util.List;
     
    1416
    1517import clarin.cmdi.componentregistry.model.AbstractDescription;
    16 import clarin.cmdi.componentregistry.rest.RegistryTestHelper;
    1718
    1819/**
     
    2627    @Autowired
    2728    protected JdbcTemplate jdbcTemplate;
     29
     30    @Autowired
     31    private UserDao userDao;
    2832
    2933    protected abstract AbstractDescriptionDao getDao();
     
    4953        description.setRegistrationDate(regDate);
    5054
    51         String testComponent = RegistryTestHelper.getComponentTestContentString();
     55        String testComponent = getContentString();
    5256        Number newId = getDao().insertDescription(description, testComponent, true, null);
    5357        assertNotNull(newId);
     
    6165        assertEquals("http://MyHref", descr.getHref());
    6266        assertEquals(AbstractDescription.getDate(regDate), AbstractDescription.getDate(descr.getRegistrationDate()));
    63         assertEquals(testComponent, getDao().getContent(description.getId()));
     67        assertEquals(testComponent, getDao().getContent(false, description.getId()));
    6468    }
    6569
     
    8185        description.setName("Aap");
    8286        description.setDescription("MyDescription");
    83         String testComponent = RegistryTestHelper.getComponentTestContentString();
     87        String testComponent = getContentString();
    8488
    8589        int count = getDao().getPublicDescriptions().size();
     
    9498        getDao().setDeleted(description, true);
    9599        assertEquals(count, getDao().getPublicDescriptions().size());
    96        
     100
    97101        deletedDescriptions = getDao().getDeletedDescriptions(null);
    98102        assertEquals(1, deletedDescriptions.size());
     
    109113        description.setHref("http://MyHref");
    110114
    111         String testComponent = RegistryTestHelper.getComponentTestContentString();
     115        String testComponent = getContentString();
    112116        Number newId = getDao().insertDescription(description, testComponent, true, null);
    113117
     
    135139        getDao().updateDescription(newId, null, testContent2);
    136140        // Test if new content is there
    137         assertEquals(testContent2, getDao().getContent(description.getId()));
     141        assertEquals(testContent2, getDao().getContent(false, description.getId()));
    138142
    139143        // Update both
     
    150154        assertEquals("YetAnotherDescription", description.getDescription());
    151155        // Test if new content is there
    152         assertEquals(testContent3, getDao().getContent(description.getId()));
     156        assertEquals(testContent3, getDao().getContent(false, description.getId()));
    153157    }
     158
     159    @Test
     160    public void testIsPublic() {
     161        Number userId = userDao.insertUser(UserDaoTest.createTestUser());
     162        AbstractDescription publicDesc = insert(true, null);
     163        assertTrue(getDao().isPublic(publicDesc.getId()));
     164        assertFalse(getDao().isInUserSpace(publicDesc.getId(), userId));
     165       
     166        AbstractDescription privateDesc = insert(false, userId);
     167        assertFalse(getDao().isPublic(privateDesc.getId()));
     168        assertTrue(getDao().isInUserSpace(privateDesc.getId(), userId));
     169       
     170        getDao().setDeleted(publicDesc, true);
     171        assertTrue(getDao().isPublic(publicDesc.getId()));
     172        assertFalse(getDao().isInUserSpace(publicDesc.getId(), userId));
     173       
     174        getDao().setDeleted(privateDesc, true);
     175        assertFalse(getDao().isPublic(privateDesc.getId()));
     176        assertTrue(getDao().isInUserSpace(privateDesc.getId(), userId));
     177    }
     178
     179    private AbstractDescription insert(boolean isPublic, Number userId) {
     180        AbstractDescription desc = createNewDescription();
     181        desc.setName("Aap");
     182        desc.setDescription("MyDescription");
     183        getDao().insertDescription(desc, getContentString(), isPublic, userId);
     184        return desc;
     185    }
     186
     187    protected abstract String getContentString();
    154188
    155189    protected abstract AbstractDescription createNewDescription();
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentDescriptionDaoTest.java

    r1361 r1364  
    7070        assertEquals(0, count);
    7171    }
     72
     73    @Override
     74    protected String getContentString() {
     75        return RegistryTestHelper.getComponentTestContentString();
     76    }
    7277}
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImplTest.java

    r1358 r1364  
    241241        registry.deleteMDComponent(description.getId(), PRINCIPAL_ADMIN, false);
    242242        assertEquals(0, registry.getComponentDescriptions().size());
    243         assertNull(registry.getMDProfile(description.getId()));
     243        assertNull(registry.getMDComponent(description.getId()));
    244244    }
    245245
     
    260260        registry.deleteMDComponent(description.getId(), PRINCIPAL_ADMIN, false);
    261261        assertEquals(0, registry.getComponentDescriptions().size());
    262         assertNull(registry.getMDProfile(description.getId()));
     262        assertNull(registry.getMDComponent(description.getId()));
    263263    }
    264264
     
    514514        description.setDescription("AnotherDescription");
    515515        // Update in db
    516         register.update(description, testComponent);
     516        register.update(description, testComponent, PRINCIPAL_ADMIN, false);
    517517        description = register.getComponentDescription(description.getId());
    518518        // Test if new values are there
     
    523523        // Update content
    524524        CMDComponentSpec testComponent2 = RegistryTestHelper.getTestComponent("Test2");
    525         register.update(description, testComponent2);
     525        register.update(description, testComponent2, PRINCIPAL_ADMIN, false);
    526526        // Test if new content is there
    527527        assertEquals(RegistryTestHelper.getXml(testComponent2),
     
    536536
    537537        // Update in db
    538         register.update(description, testComponent3);
     538        register.update(description, testComponent3, PRINCIPAL_ADMIN, false);
    539539        description = register.getComponentDescription(description.getId());
    540540        // Test if new values are there
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ProfileDescriptionDaoTest.java

    r1332 r1364  
    44import clarin.cmdi.componentregistry.model.AbstractDescription;
    55import clarin.cmdi.componentregistry.model.ProfileDescription;
     6import clarin.cmdi.componentregistry.rest.RegistryTestHelper;
    67
    78import org.junit.Before;
     
    3435        return ProfileDescription.createNewDescription();
    3536    }
     37   
     38    @Override
     39    protected String getContentString() {
     40        return RegistryTestHelper.getProfileTestContentString();
     41    }
     42
    3643}
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/filesystem/AdminRegistryTest.java

    r1342 r1364  
    11package clarin.cmdi.componentregistry.impl.filesystem;
    22
    3 import clarin.cmdi.componentregistry.DeleteFailedException;
    4 import clarin.cmdi.componentregistry.impl.filesystem.AdminRegistry;
    5 import clarin.cmdi.componentregistry.impl.filesystem.ComponentRegistryImpl;
     3import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableComponentDescription;
     4import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableProfileDescription;
     5import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableRegistryUser;
     6import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableXmlContent;
     7import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.resetDatabase;
    68import static org.junit.Assert.assertEquals;
    79import static org.junit.Assert.assertTrue;
    810import static org.junit.Assert.fail;
    911
    10 import java.io.File;
     12import java.security.Principal;
    1113
     14import org.junit.Before;
    1215import org.junit.Test;
     16import org.junit.runner.RunWith;
     17import org.springframework.beans.factory.annotation.Autowired;
     18import org.springframework.jdbc.core.JdbcTemplate;
     19import org.springframework.test.context.ContextConfiguration;
     20import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    1321
    14 import clarin.cmdi.componentregistry.frontend.FileInfo;
    15 import clarin.cmdi.componentregistry.frontend.FileNode;
     22import clarin.cmdi.componentregistry.ComponentRegistry;
     23import clarin.cmdi.componentregistry.ComponentRegistryFactory;
     24import clarin.cmdi.componentregistry.DeleteFailedException;
     25import clarin.cmdi.componentregistry.frontend.CMDItemInfo;
     26import clarin.cmdi.componentregistry.frontend.DisplayDataNode;
    1627import clarin.cmdi.componentregistry.frontend.SubmitFailedException;
     28import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao;
     29import clarin.cmdi.componentregistry.impl.database.ProfileDescriptionDao;
    1730import clarin.cmdi.componentregistry.model.ComponentDescription;
    1831import clarin.cmdi.componentregistry.model.ProfileDescription;
     32import clarin.cmdi.componentregistry.rest.DummyPrincipal;
    1933import clarin.cmdi.componentregistry.rest.RegistryTestHelper;
    2034
    21 public class AdminRegistryTest extends ComponentRegistryTestCase {
     35@RunWith(SpringJUnit4ClassRunner.class)
     36@ContextConfiguration(locations = {"/applicationContext-database-impl.xml"})
     37public class AdminRegistryTest  {
     38   
     39    @Autowired
     40    private ComponentDescriptionDao componentDescriptionDao;
     41    @Autowired
     42    private ProfileDescriptionDao profileDescriptionDao;
     43    @Autowired
     44    private ComponentRegistryFactory componentRegistryFactory;
     45    private static final Principal PRINCIPAL_ADMIN = DummyPrincipal.DUMMY_ADMIN_PRINCIPAL;
     46   
     47    @Autowired
     48    private JdbcTemplate jdbcTemplate;
     49    @Before
     50    public void init() { //TODO PD make super testcase and share with other test classes that have this. Also move this class to db package.
     51                        //TODO PD should we also check publish for the right user?
     52        resetDatabase(jdbcTemplate);
     53        createTableComponentDescription(jdbcTemplate);
     54        createTableProfileDescription(jdbcTemplate);
     55        createTableXmlContent(jdbcTemplate);
     56        createTableRegistryUser(jdbcTemplate);
     57    }
    2258
    2359    @Test
    2460    public void testForceUpdate() throws Exception {
    25         ComponentRegistryImpl testRegistry = getTestRegistry();
    26         String content = "";
    27         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    28         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    29         content += "    <Header/>\n";
    30         content += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
    31         content += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    32         content += "    </CMD_Component>\n";
    33         content += "</CMD_ComponentSpec>\n";
    34         ComponentDescription compDesc1 = RegistryTestHelper.addComponent(testRegistry, "XXX1", content);
     61        ComponentRegistry testRegistry = componentRegistryFactory.getPublicRegistry();
     62        String content1 = "";
     63        content1 += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     64        content1 += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     65        content1 += "    <Header/>\n";
     66        content1 += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
     67        content1 += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
     68        content1 += "    </CMD_Component>\n";
     69        content1 += "</CMD_ComponentSpec>\n";
     70        ComponentDescription compDesc1 = RegistryTestHelper.addComponent(testRegistry, "XXX1", content1);
    3571
    36         content = "";
    37         content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    38         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    39         content += "    <Header/>\n";
    40         content += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    41         content += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    42         content += "        </CMD_Component>\n";
    43         content += "    </CMD_Component>\n";
    44         content += "</CMD_ComponentSpec>\n";
    45         ProfileDescription profileDesc = RegistryTestHelper.addProfile(testRegistry, "YYY1", content);
     72        String content2 = "";
     73        content2 += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     74        content2 += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     75        content2 += "    <Header/>\n";
     76        content2 += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     77        content2 += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     78        content2 += "        </CMD_Component>\n";
     79        content2 += "    </CMD_Component>\n";
     80        content2 += "</CMD_ComponentSpec>\n";
     81        ProfileDescription profileDesc = RegistryTestHelper.addProfile(testRegistry, "YYY1", content2);
    4682
    4783        AdminRegistry adminReg = new AdminRegistry();
    48         FileInfo fileInfo = new FileInfo();
     84        adminReg.setComponentRegistryFactory(componentRegistryFactory);
     85        adminReg.setComponentDescriptionDao(componentDescriptionDao);
     86        adminReg.setProfileDescriptionDao(profileDescriptionDao);
     87        CMDItemInfo fileInfo = new CMDItemInfo();
    4988        fileInfo.setForceUpdate(false);
    50         fileInfo.setDisplayNode(new FileNode(new File(getRegistryDir(), "components" + File.separator + compDesc1.getName() + File.separator
    51                 + compDesc1.getName() + ".xml"), false));
     89        fileInfo.setDataNode(new DisplayDataNode(compDesc1.getName(), false, compDesc1, true));
     90        fileInfo.setContent(content1);
    5291        try {
    5392            adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN);
    5493            fail();
    55         } catch (SubmitFailedException e) {
    56             assertTrue(e.getCause() instanceof DeleteFailedException);
    57         }
     94        } catch (SubmitFailedException e) {}
    5895        fileInfo.setForceUpdate(true);
    5996        adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); //Component needs to be forced because they can be used by other profiles/components
     
    74111        assertEquals(1, testRegistry.getProfileDescriptions().size());
    75112        fileInfo.setForceUpdate(false);
    76         fileInfo.setDisplayNode(new FileNode(new File(getRegistryDir(), "profiles" + File.separator + profileDesc.getName() + File.separator
    77                 + profileDesc.getName() + ".xml"), false));
     113        fileInfo.setDataNode(new DisplayDataNode(profileDesc.getName(), false, profileDesc, true));
    78114        adminReg.delete(fileInfo, PRINCIPAL_ADMIN); //Profile do not need to be forced they cannot be used by other profiles
    79115        assertEquals(0, testRegistry.getProfileDescriptions().size());
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/filesystem/CMDComponentSpecExpanderTest.java

    r1334 r1364  
    33import static org.junit.Assert.assertEquals;
    44
    5 import java.io.File;
    65import java.util.List;
    76
     
    1716public class CMDComponentSpecExpanderTest extends ComponentRegistryTestCase{
    1817
    19     private File tmpRegistryDir;
    2018
    2119    @Test
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryImplTest.java

    r1352 r1364  
    388388
    389389        assertEquals(0, registry.getComponentDescriptions().size());
    390         assertNull(registry.getMDProfile(description.getId()));
     390        assertNull(registry.getMDComponent(description.getId()));
    391391    }
    392392
     
    480480        assertEquals("MyDescription", desc.getDescription());
    481481        desc.setDescription("NewDesc");
    482         registry.update(desc, testComponent);
     482        registry.update(desc, testComponent, PRINCIPAL_ADMIN, false);
    483483
    484484        registry = getTestRegistry(getRegistryDir());
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryTestCase.java

    r1333 r1364  
    11package clarin.cmdi.componentregistry.impl.filesystem;
    22
    3 import clarin.cmdi.componentregistry.ComponentRegistryFactory;
    4 import clarin.cmdi.componentregistry.Configuration;
    5 import clarin.cmdi.componentregistry.UserCredentials;
    63import static org.junit.Assert.assertTrue;
    74
    85import java.io.File;
    96import java.security.Principal;
     7import java.util.Arrays;
    108import java.util.HashSet;
    119import java.util.Set;
     
    1311import org.apache.commons.io.FileUtils;
    1412import org.junit.After;
    15 
    16 import clarin.cmdi.componentregistry.rest.DummyPrincipal;
    17 import java.util.Arrays;
    1813import org.junit.runner.RunWith;
    1914import org.springframework.beans.factory.annotation.Autowired;
     
    2116import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    2217
     18import clarin.cmdi.componentregistry.ComponentRegistryFactory;
     19import clarin.cmdi.componentregistry.Configuration;
     20import clarin.cmdi.componentregistry.UserCredentials;
     21import clarin.cmdi.componentregistry.rest.DummyPrincipal;
     22
    2323@RunWith(SpringJUnit4ClassRunner.class)
    24 @ContextConfiguration(locations={"/applicationContext-filesystem-impl.xml"})
     24@ContextConfiguration(locations = { "/applicationContext-filesystem-impl.xml" })
    2525public abstract class ComponentRegistryTestCase {
    2626
    2727    @Autowired
    2828    protected ComponentRegistryFactory componentRegistryFactory;
     29
    2930
    3031    protected File tmpRegistryDir;
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java

    r1345 r1364  
    22
    33import java.io.ByteArrayInputStream;
     4import java.io.ByteArrayOutputStream;
    45import java.io.IOException;
    56import java.io.InputStream;
     
    89import java.text.ParseException;
    910import java.text.SimpleDateFormat;
     11import java.util.regex.Matcher;
     12import java.util.regex.Pattern;
    1013
    1114import javax.xml.bind.JAXBException;
     
    1619import clarin.cmdi.componentregistry.model.ComponentDescription;
    1720import clarin.cmdi.componentregistry.model.ProfileDescription;
    18 import java.io.ByteArrayOutputStream;
    19 import java.util.regex.Matcher;
    20 import java.util.regex.Pattern;
    2121
    2222/**
     
    2626public final class RegistryTestHelper {
    2727
    28     private final static DateFormat ISO_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
     28    private final static DateFormat ISO_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");//TODO PD this is no longer user but do we still have same dates?
    2929
    3030    private RegistryTestHelper() {
     
    3737    public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content) throws ParseException,
    3838            JAXBException, UnsupportedEncodingException {
    39         return addComponent(testRegistry, id, new ByteArrayInputStream(content.
    40                 getBytes("UTF-8")));
     39        return addComponent(testRegistry, id, new ByteArrayInputStream(content.getBytes("UTF-8")));
    4140    }
    4241
     
    5049        desc.setId(ComponentRegistry.REGISTRY_ID + id);
    5150        desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id);
    52         CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.
    53                 getCMDComponentSchema());
     51        CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema());
    5452        testRegistry.register(desc, spec);
    5553        return desc;
    5654    }
    5755
    58     public static InputStream getTestProfileContent() {
    59         return getTestProfileContent("Actor");
     56    public static String getProfileTestContentString() {
     57        return getProfileTestContentString("Actor");
    6058    }
    6159
    62     public static InputStream getTestProfileContent(String name) {
     60    private static String getProfileTestContentString(String name) {
    6361        String profileContent = "";
    6462        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    8078        profileContent += "    </CMD_Component>\n";
    8179        profileContent += "</CMD_ComponentSpec>\n";
    82         return new ByteArrayInputStream(profileContent.getBytes());
     80        return profileContent;
     81    }
     82
     83    public static InputStream getTestProfileContent() {
     84        return getTestProfileContent("Actor");
     85    }
     86
     87    public static InputStream getTestProfileContent(String name) {
     88        return new ByteArrayInputStream(getProfileTestContentString(name).getBytes());
    8389    }
    8490
    8591    public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id) throws ParseException, JAXBException {
    86         return addProfile(testRegistry, id, RegistryTestHelper.
    87                 getTestProfileContent());
     92        return addProfile(testRegistry, id, RegistryTestHelper.getTestProfileContent());
    8893    }
    8994
    9095    public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id, String content) throws ParseException,
    9196            JAXBException {
    92         return addProfile(testRegistry, id, new ByteArrayInputStream(content.
    93                 getBytes()));
     97        return addProfile(testRegistry, id, new ByteArrayInputStream(content.getBytes()));
    9498    }
    9599
     
    103107        desc.setId(ComponentRegistry.REGISTRY_ID + id);
    104108        desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id);
    105         CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.
    106                 getCMDComponentSchema());
     109        CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema());
    107110        testRegistry.register(desc, spec);
    108111        return desc;
     
    110113
    111114    public static CMDComponentSpec getTestProfile() throws JAXBException {
    112         return MDMarshaller.unmarshal(CMDComponentSpec.class, getTestProfileContent(), MDMarshaller.
    113                 getCMDComponentSchema());
     115        return MDMarshaller.unmarshal(CMDComponentSpec.class, getTestProfileContent(), MDMarshaller.getCMDComponentSchema());
    114116    }
    115117
     
    148150
    149151    public static InputStream getComponentTestContent(String componentName) {
    150         return new ByteArrayInputStream(getComponentTestContentString(componentName).
    151                 getBytes());
     152        return new ByteArrayInputStream(getComponentTestContentString(componentName).getBytes());
    152153    }
    153154
    154155    public static CMDComponentSpec getTestComponent() throws JAXBException {
    155         return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(), MDMarshaller.
    156                 getCMDComponentSchema());
     156        return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(), MDMarshaller.getCMDComponentSchema());
    157157    }
    158158
    159159    public static CMDComponentSpec getTestComponent(String name) throws JAXBException {
    160         return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(name), MDMarshaller.
    161                 getCMDComponentSchema());
     160        return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(name), MDMarshaller.getCMDComponentSchema());
    162161    }
    163162
     
    182181        return matcher.find() && !matcher.find(); //find only one
    183182    }
     183
    184184}
Note: See TracChangeset for help on using the changeset viewer.