Changeset 1364
- Timestamp:
- 05/23/11 16:00:21 (13 years ago)
- 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 37 37 * @return -1 if component could not be updated 38 38 */ 39 int update(AbstractDescription description, CMDComponentSpec spec );39 int update(AbstractDescription description, CMDComponentSpec spec, Principal principal, boolean forceUpdate); 40 40 41 41 /** … … 108 108 List<ComponentDescription> getDeletedComponentDescriptions(); 109 109 110 110 111 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/AdminHomePage.html
r1342 r1364 21 21 </div> 22 22 <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" />forceUpdate27 <textarea class="infoTextArea" wicket:id="text" >text</textarea>28 <button wicket:id="submit">submit</button>29 </form>30 23 <div id="feedbackPanel"> 31 24 <span wicket:id="feedback"></span> 32 25 </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> 33 34 </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>39 35 </div> 40 36 </body> -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/AdminHomePage.java
r1352 r1364 1 1 package clarin.cmdi.componentregistry.frontend; 2 2 3 import clarin.cmdi.componentregistry.ComponentRegistryException;4 import java.io.File;5 3 import java.security.Principal; 6 import java.util.ArrayList;7 4 import java.util.List; 8 5 … … 30 27 31 28 import clarin.cmdi.componentregistry.ComponentRegistry; 29 import clarin.cmdi.componentregistry.ComponentRegistryException; 32 30 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 31 import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao; 32 import clarin.cmdi.componentregistry.impl.database.ProfileDescriptionDao; 33 33 import clarin.cmdi.componentregistry.impl.filesystem.AdminRegistry; 34 import clarin.cmdi.componentregistry.impl.filesystem.FileSystemConfiguration;35 import clarin.cmdi.componentregistry.impl.filesystem.ResourceConfig;36 34 import clarin.cmdi.componentregistry.model.AbstractDescription; 35 import clarin.cmdi.componentregistry.model.ComponentDescription; 36 import clarin.cmdi.componentregistry.model.ProfileDescription; 37 37 38 38 @SuppressWarnings("serial") … … 41 41 private final static Logger LOG = LoggerFactory.getLogger(AdminHomePage.class); 42 42 43 private final FileInfo fileInfo = new FileInfo();43 private final CMDItemInfo info = new CMDItemInfo(); 44 44 private final LinkTree tree; 45 45 46 46 private transient AdminRegistry adminRegistry = new AdminRegistry(); 47 47 48 @SpringBean(name ="componentRegistryFactory")48 @SpringBean(name = "componentRegistryFactory") 49 49 private ComponentRegistryFactory componentRegistryFactory; 50 @SpringBean 51 private ProfileDescriptionDao profileDescriptionDao; 52 @SpringBean 53 private ComponentDescriptionDao componentDescriptionDao; 50 54 51 55 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 162 173 } 163 174 164 175 private void addLinks() { 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 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 }); 184 195 } 185 196 186 197 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 } 242 242 243 243 } 244 244 245 245 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; 260 259 } 261 260 262 261 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 } 285 287 } 286 288 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/CMDItemInfo.java
r1342 r1364 3 3 import java.io.Serializable; 4 4 5 public class FileInfo implements Serializable { 5 import clarin.cmdi.componentregistry.MDMarshaller; 6 import clarin.cmdi.componentregistry.model.AbstractDescription; 7 8 public class CMDItemInfo implements Serializable { 6 9 7 10 private static final long serialVersionUID = 1L; 8 11 9 private String text; 12 private String description; 13 private String content; 10 14 private String name; 11 15 private boolean forceUpdate = false; 12 16 13 private Display Node displayNode;17 private DisplayDataNode displayNode; 14 18 15 19 private boolean deletable = false; … … 18 22 private boolean editable = false; 19 23 20 public void set Text(String text) {21 this. text = text;24 public void setDescription(String descriptionText) { 25 this.description = descriptionText; 22 26 } 23 27 24 public String get Text() {25 return text;28 public String getDescription() { 29 return description; 26 30 } 27 31 … … 37 41 } 38 42 39 public Display Node getDisplayNode() {43 public DisplayDataNode getDataNode() { 40 44 return displayNode; 41 45 } 42 46 43 public void setD isplayNode(DisplayNode displayNode) {44 this.displayNode = d isplayNode;47 public void setDataNode(DisplayDataNode dataNode) { 48 this.displayNode = dataNode; 45 49 setUndeletable(false); 46 50 setDeletable(false); 47 51 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()) { 56 61 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 { 59 63 setDeletable(true); 60 } else { 61 setText(""); 62 } 64 } 63 65 } 64 66 } … … 90 92 } 91 93 92 public boolean isComponent() {93 return getName().startsWith("c_");94 }95 94 96 95 public boolean isInUserWorkSpace() { 97 return displayNode.isUserNode();96 return !displayNode.isPublic(); 98 97 } 99 98 … … 106 105 } 107 106 107 public void setContent(String content) { 108 this.content = content; 109 } 110 111 public String getContent() { 112 return content; 113 } 114 108 115 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/DisplayDataNode.java
r1342 r1364 3 3 import java.io.Serializable; 4 4 5 public class DisplayDataNode implements Serializable, DisplayNode { 5 import clarin.cmdi.componentregistry.model.AbstractDescription; 6 7 public class DisplayDataNode implements Serializable { 6 8 7 9 private static final long serialVersionUID = 1L; 8 10 private final String name; 9 11 private final boolean isDeleted; 12 private AbstractDescription desc; 13 private final boolean isPublic; 10 14 11 15 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) { 12 20 this.name = name; 13 21 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; 14 36 } 15 37 … … 19 41 } 20 42 21 @Override 22 public String getContent() { 23 // TODO Auto-generated method stub 24 return null; 43 public boolean isPublic() { 44 return isPublic; 25 45 } 26 46 27 @Override28 public boolean hasContent() {29 // TODO Auto-generated method stub30 return false;31 }32 33 @Override34 public boolean isDeleted() {35 return isDeleted;36 }37 38 @Override39 public boolean isEditable() {40 // TODO Auto-generated method stub41 return false;42 }43 44 @Override45 public boolean isUserNode() {46 // TODO Auto-generated method stub47 return false;48 }49 50 @Override51 public String getId() {52 // TODO Auto-generated method stub53 return null;54 }55 47 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/MassMigratePage.java
r1352 r1364 1 1 package clarin.cmdi.componentregistry.frontend; 2 2 3 import clarin.cmdi.componentregistry.ComponentRegistryException;4 import java.io.ByteArrayOutputStream;5 3 import java.io.Serializable; 6 import java.io.UnsupportedEncodingException;7 4 import java.util.ArrayList; 8 5 import java.util.List; 9 import java.util.logging.Level;10 11 import javax.xml.bind.JAXBException;12 6 13 7 import org.apache.wicket.Component; … … 25 19 26 20 import clarin.cmdi.componentregistry.ComponentRegistry; 21 import clarin.cmdi.componentregistry.ComponentRegistryException; 27 22 import clarin.cmdi.componentregistry.MDMarshaller; 28 23 import clarin.cmdi.componentregistry.components.CMDComponentSpec; … … 127 122 descDao.insertDescription(description, getContent(description, registry), registry.isPublic(), user.getId()); 128 123 } catch (Exception e) { 129 LOG.error("Error in migration , check the logs!", e);130 info("Error cannot migrate 124 LOG.error("Error in migration:", e); 125 info("Error cannot migrate, check the logs!" + description.getId()); 131 126 } 132 127 migrateCount++; … … 135 130 } 136 131 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 { 141 133 CMDComponentSpec spec = null; 142 134 if (description.isProfile()) { … … 145 137 spec = registry.getMDComponent(description.getId()); 146 138 } 147 MDMarshaller.marshal(spec, out); 148 return out.toString(); 139 return MDMarshaller.marshalToString(spec); 149 140 } 150 141 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java
r1352 r1364 1 1 package clarin.cmdi.componentregistry.impl; 2 3 import java.io.OutputStream; 4 import java.io.UnsupportedEncodingException; 5 import java.util.ArrayList; 6 import java.util.List; 7 8 import javax.xml.bind.JAXBException; 9 10 import org.apache.commons.lang.StringUtils; 11 import org.slf4j.Logger; 12 import org.slf4j.LoggerFactory; 2 13 3 14 import clarin.cmdi.componentregistry.ComponentRegistry; … … 5 16 import clarin.cmdi.componentregistry.DeleteFailedException; 6 17 import clarin.cmdi.componentregistry.MDMarshaller; 7 import clarin.cmdi.componentregistry.UserUnauthorizedException;8 18 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 19 import clarin.cmdi.componentregistry.components.CMDComponentType; 9 20 import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header; 10 import clarin.cmdi.componentregistry.components.CMDComponentType;11 21 import clarin.cmdi.componentregistry.model.AbstractDescription; 12 22 import clarin.cmdi.componentregistry.model.ComponentDescription; 13 23 import 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;24 24 25 25 /** 26 * 26 * 27 27 * @author Twan Goosen <twan.goosen@mpi.nl> 28 28 */ … … 123 123 } 124 124 125 /* UNIMPLEMENTED INTERFACE METHODS */126 @Override127 public abstract List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException;128 129 @Override130 public abstract ComponentDescription getComponentDescription(String id) throws ComponentRegistryException;131 132 @Override133 public abstract List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException;134 135 @Override136 public abstract ProfileDescription getProfileDescription(String id) throws ComponentRegistryException;137 138 @Override139 public abstract CMDComponentSpec getMDProfile(String id) throws ComponentRegistryException;140 141 @Override142 public abstract CMDComponentSpec getMDComponent(String id) throws ComponentRegistryException;143 144 @Override145 public abstract int register(AbstractDescription desc, CMDComponentSpec spec);146 147 @Override148 public abstract int update(AbstractDescription description, CMDComponentSpec spec);149 150 @Override151 public abstract int publish(AbstractDescription desc, CMDComponentSpec spec, Principal principal);152 153 @Override154 public abstract void getMDProfileAsXml(String profileId, OutputStream output) throws ComponentRegistryException;155 156 @Override157 public abstract void getMDProfileAsXsd(String profileId, OutputStream outputStream) throws ComponentRegistryException;158 159 @Override160 public abstract void getMDComponentAsXml(String componentId, OutputStream output) throws ComponentRegistryException;161 162 @Override163 public abstract void getMDComponentAsXsd(String componentId, OutputStream outputStream) throws ComponentRegistryException;164 165 @Override166 public abstract void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException, DeleteFailedException, ComponentRegistryException;167 168 @Override169 public abstract void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException, DeleteFailedException, ComponentRegistryException;170 171 @Override172 public abstract boolean isPublic();173 125 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/AbstractDescriptionDao.java
r1362 r1364 56 56 * @param cmdId 57 57 * 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 60 59 */ 61 60 public boolean isPublic(String cmdId) { 62 61 StringBuilder query = new StringBuilder("SELECT COUNT(*) FROM "); 63 62 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(" = ?"); 65 64 return (0 < getSimpleJdbcTemplate().queryForInt(query.toString(), cmdId)); 66 65 } … … 72 71 * @param userId 73 72 * 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 76 74 */ 77 75 public boolean isInUserSpace(String cmdId, Number userId) { 78 76 StringBuilder query = new StringBuilder("SELECT COUNT(*) FROM "); 79 77 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(" = ?"); 81 79 return (0 < getSimpleJdbcTemplate().queryForInt(query.toString(), userId, cmdId)); 82 80 } … … 88 86 * @return String value of XML content for profile or component 89 87 */ 90 public String getContent( String cmdId) throws DataAccessException {88 public String getContent(boolean isDeleted, String cmdId) throws DataAccessException { 91 89 String select = "SELECT content FROM " + TABLE_XML_CONTENT + " JOIN " + getTableName() + " ON " + TABLE_XML_CONTENT + "." 92 + COLUMN_ID + " = " + getTableName() + ".content_id" + " WHERE is_deleted = falseAND " + getTableName() + "."90 + COLUMN_ID + " = " + getTableName() + ".content_id" + " WHERE is_deleted = ? AND " + getTableName() + "." 93 91 + getCMDIdColumn() + " = ?"; 94 92 95 List<String> result = getSimpleJdbcTemplate().query(select, new ParameterizedSingleColumnRowMapper<String>(), cmdId);93 List<String> result = getSimpleJdbcTemplate().query(select, new ParameterizedSingleColumnRowMapper<String>(), isDeleted, cmdId); 96 94 if (result.size() > 0) { 97 95 return result.get(0); … … 262 260 * @param userId 263 261 */ 264 public List<T> getDeletedDescriptions(Number userId) { //TODO PD make test!262 public List<T> getDeletedDescriptions(Number userId) { 265 263 if (userId != null) { 266 264 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 217 217 218 218 @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 } 221 226 AbstractDescriptionDao<?> dao = getDaoForDescription(description); 222 227 dao.updateDescription(getIdForDescription(description), description, componentSpecToString(spec)); 223 228 invalidateCache(description); 224 229 return 0; 225 } catch (DataAccessException ex) {226 LOG.error("Database error while updating component", ex);227 return -1;228 230 } catch (JAXBException ex) { 229 231 LOG.error("Error while updating component", ex); 230 return - 2;232 return -1; 231 233 } catch (UnsupportedEncodingException ex) { 232 234 LOG.error("Error while updating component", ex); 233 return - 3;235 return -1; 234 236 } catch (IllegalArgumentException ex) { 235 237 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; 237 248 } 238 249 } … … 242 253 int result = 0; 243 254 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 246 256 desc.setHref(AbstractDescription.createPublicHref(desc.getHref())); 247 257 Number id = getIdForDescription(desc); … … 395 405 396 406 private CMDComponentSpec getUncachedMDComponent(String id, AbstractDescriptionDao dao) { 397 String xml = dao.getContent( id);407 String xml = dao.getContent(false, id); 398 408 if (xml != null) { 399 409 try { -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/filesystem/AdminRegistry.java
r1352 r1364 1 1 package clarin.cmdi.componentregistry.impl.filesystem; 2 2 3 import clarin.cmdi.componentregistry.ComponentRegistryException;4 import java.io.File;5 import java.io.FileInputStream;6 import java.io.FileNotFoundException;7 3 import java.io.IOException; 8 4 import java.security.Principal; … … 10 6 import javax.xml.bind.JAXBException; 11 7 12 import org.apache.commons.io.FileUtils;13 8 import org.apache.commons.io.IOUtils; 14 9 import org.slf4j.Logger; 15 10 import org.slf4j.LoggerFactory; 11 import org.springframework.dao.DataAccessException; 16 12 17 13 import clarin.cmdi.componentregistry.ComponentRegistry; 14 import clarin.cmdi.componentregistry.ComponentRegistryException; 15 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 18 16 import clarin.cmdi.componentregistry.DeleteFailedException; 19 17 import clarin.cmdi.componentregistry.MDMarshaller; 20 18 import clarin.cmdi.componentregistry.UserUnauthorizedException; 21 19 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 22 import clarin.cmdi.componentregistry.frontend.FileInfo; 23 import clarin.cmdi.componentregistry.frontend.FileNode; 20 import clarin.cmdi.componentregistry.frontend.CMDItemInfo; 24 21 import clarin.cmdi.componentregistry.frontend.SubmitFailedException; 22 import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao; 23 import clarin.cmdi.componentregistry.impl.database.ProfileDescriptionDao; 25 24 import clarin.cmdi.componentregistry.model.AbstractDescription; 26 25 import clarin.cmdi.componentregistry.model.ComponentDescription; … … 28 27 29 28 public class AdminRegistry { 30 31 29 private final static Logger LOG = LoggerFactory.getLogger(AdminRegistry.class); 32 30 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 { 34 48 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); 39 54 } 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."); 73 64 } 74 65 } catch (JAXBException e) { … … 76 67 } catch (IOException e) { 77 68 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);84 69 } 85 86 70 } 87 71 … … 92 76 } 93 77 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(); 97 80 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); 103 83 } else { 104 throw new SubmitFailedException("Problem occured while registering, please check the tomcat logs for errors.");84 componentDescriptionDao.setDeleted(desc, false); 105 85 } 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); 110 88 } 111 112 89 } 113 90 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(); 117 94 try { 118 deleteFromRegistry(userPrincipal, desc, fileInfo);95 deleteFromRegistry(userPrincipal, desc, info); 119 96 LOG.info("Deleted item: " + id); 120 97 } catch (IOException e) { … … 130 107 } 131 108 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); 145 112 LOG.info("Deleting item: " + desc); 146 113 if (desc.isProfile()) { 147 114 registry.deleteMDProfile(desc.getId(), userPrincipal); 148 115 } else { 149 registry.deleteMDComponent(desc.getId(), userPrincipal, fileInfo.isForceUpdate());116 registry.deleteMDComponent(desc.getId(), userPrincipal, info.isForceUpdate()); 150 117 } 151 118 } 152 119 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()); 157 124 } 158 125 return registry; 159 126 } 160 127 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 }186 128 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryImpl.java
r1359 r1364 275 275 276 276 @Override 277 public int update(AbstractDescription desc, CMDComponentSpec spec ) {277 public int update(AbstractDescription desc, CMDComponentSpec spec, Principal principal, boolean forceUpdate) { 278 278 LOG.info("Attempt to update " + desc.getType() + ": " + desc); 279 279 return register(getDir(desc), desc, spec, new UpdateClosureOnFail(desc)); … … 468 468 throw new NotImplementedException(); 469 469 } 470 470 471 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r1352 r1364 255 255 if (desc != null) { 256 256 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)); 258 258 } else { 259 259 LOG.error("Update of nonexistent id (" + profileId + ") failed."); … … 320 320 if (desc != null) { 321 321 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)); 323 323 } else { 324 324 LOG.error("Update of nonexistent id (" + componentId + ") failed."); -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/UpdateAction.java
r1087 r1364 1 1 package clarin.cmdi.componentregistry.rest; 2 3 import java.security.Principal; 2 4 3 5 import clarin.cmdi.componentregistry.ComponentRegistry; … … 7 9 8 10 public class UpdateAction implements RegisterAction { 11 12 private final Principal principal; 9 13 14 public UpdateAction(Principal principal) { 15 this.principal = principal; 16 } 17 10 18 @Override 11 19 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); 13 21 } 14 22 -
ComponentRegistry/trunk/ComponentRegistry/src/main/webapp/css/adminstyle.css
r622 r1364 16 16 } 17 17 18 textArea. infoTextArea {18 textArea.contentTextArea { 19 19 width: 100%; 20 20 height: 500px; 21 21 } 22 23 textArea.descriptionTextArea { 24 width: 100%; 25 height: 200px; 26 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/frontend/CMDItemInfoTest.java
r1342 r1364 1 1 package clarin.cmdi.componentregistry.frontend; 2 2 3 import static org.junit.Assert.assertEquals; 3 4 import static org.junit.Assert.assertFalse; 4 5 import static org.junit.Assert.assertTrue; 5 6 6 import java.io.File;7 import java.io.IOException;8 9 import org.apache.commons.io.FileUtils;10 import org.junit.After;11 7 import org.junit.Test; 12 8 13 import clarin.cmdi.componentregistry. impl.filesystem.ComponentRegistryTestCase;14 import clarin.cmdi.componentregistry. impl.filesystem.FileSystemConfiguration;9 import clarin.cmdi.componentregistry.model.AbstractDescription; 10 import clarin.cmdi.componentregistry.model.ProfileDescription; 15 11 16 public class FileInfoTest { 17 18 private File rootDir; 12 public class CMDItemInfoTest { 19 13 20 14 @Test 21 15 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()); 27 20 assertFalse(info.isUndeletable()); 28 21 assertTrue(info.isEditable()); 29 assertFalse(info.getD isplayNode().isDeleted());22 assertFalse(info.getDataNode().isDeleted()); 30 23 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)); 32 26 assertFalse(info.isDeletable()); 33 assert False(info.isUndeletable());27 assertTrue(info.isUndeletable()); 34 28 assertTrue(info.isEditable()); 35 assertTrue(info.getD isplayNode().isDeleted());29 assertTrue(info.getDataNode().isDeleted()); 36 30 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()); 39 34 assertFalse(info.isUndeletable()); 40 35 assertTrue(info.isEditable()); 41 36 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)); 58 39 assertFalse(info.isDeletable()); 59 40 assertFalse(info.isUndeletable()); 60 41 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()); 61 47 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)); 63 51 assertFalse(info.isDeletable()); 64 52 assertFalse(info.isUndeletable()); 65 53 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()); 87 55 } 88 56 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(); 104 59 } 105 60 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AbstractDescriptionDaoTest.java
r1358 r1364 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertFalse; 4 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.assertTrue; 5 7 6 8 import java.util.List; … … 14 16 15 17 import clarin.cmdi.componentregistry.model.AbstractDescription; 16 import clarin.cmdi.componentregistry.rest.RegistryTestHelper;17 18 18 19 /** … … 26 27 @Autowired 27 28 protected JdbcTemplate jdbcTemplate; 29 30 @Autowired 31 private UserDao userDao; 28 32 29 33 protected abstract AbstractDescriptionDao getDao(); … … 49 53 description.setRegistrationDate(regDate); 50 54 51 String testComponent = RegistryTestHelper.getComponentTestContentString();55 String testComponent = getContentString(); 52 56 Number newId = getDao().insertDescription(description, testComponent, true, null); 53 57 assertNotNull(newId); … … 61 65 assertEquals("http://MyHref", descr.getHref()); 62 66 assertEquals(AbstractDescription.getDate(regDate), AbstractDescription.getDate(descr.getRegistrationDate())); 63 assertEquals(testComponent, getDao().getContent( description.getId()));67 assertEquals(testComponent, getDao().getContent(false, description.getId())); 64 68 } 65 69 … … 81 85 description.setName("Aap"); 82 86 description.setDescription("MyDescription"); 83 String testComponent = RegistryTestHelper.getComponentTestContentString();87 String testComponent = getContentString(); 84 88 85 89 int count = getDao().getPublicDescriptions().size(); … … 94 98 getDao().setDeleted(description, true); 95 99 assertEquals(count, getDao().getPublicDescriptions().size()); 96 100 97 101 deletedDescriptions = getDao().getDeletedDescriptions(null); 98 102 assertEquals(1, deletedDescriptions.size()); … … 109 113 description.setHref("http://MyHref"); 110 114 111 String testComponent = RegistryTestHelper.getComponentTestContentString();115 String testComponent = getContentString(); 112 116 Number newId = getDao().insertDescription(description, testComponent, true, null); 113 117 … … 135 139 getDao().updateDescription(newId, null, testContent2); 136 140 // Test if new content is there 137 assertEquals(testContent2, getDao().getContent( description.getId()));141 assertEquals(testContent2, getDao().getContent(false, description.getId())); 138 142 139 143 // Update both … … 150 154 assertEquals("YetAnotherDescription", description.getDescription()); 151 155 // Test if new content is there 152 assertEquals(testContent3, getDao().getContent( description.getId()));156 assertEquals(testContent3, getDao().getContent(false, description.getId())); 153 157 } 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(); 154 188 155 189 protected abstract AbstractDescription createNewDescription(); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentDescriptionDaoTest.java
r1361 r1364 70 70 assertEquals(0, count); 71 71 } 72 73 @Override 74 protected String getContentString() { 75 return RegistryTestHelper.getComponentTestContentString(); 76 } 72 77 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImplTest.java
r1358 r1364 241 241 registry.deleteMDComponent(description.getId(), PRINCIPAL_ADMIN, false); 242 242 assertEquals(0, registry.getComponentDescriptions().size()); 243 assertNull(registry.getMD Profile(description.getId()));243 assertNull(registry.getMDComponent(description.getId())); 244 244 } 245 245 … … 260 260 registry.deleteMDComponent(description.getId(), PRINCIPAL_ADMIN, false); 261 261 assertEquals(0, registry.getComponentDescriptions().size()); 262 assertNull(registry.getMD Profile(description.getId()));262 assertNull(registry.getMDComponent(description.getId())); 263 263 } 264 264 … … 514 514 description.setDescription("AnotherDescription"); 515 515 // Update in db 516 register.update(description, testComponent );516 register.update(description, testComponent, PRINCIPAL_ADMIN, false); 517 517 description = register.getComponentDescription(description.getId()); 518 518 // Test if new values are there … … 523 523 // Update content 524 524 CMDComponentSpec testComponent2 = RegistryTestHelper.getTestComponent("Test2"); 525 register.update(description, testComponent2 );525 register.update(description, testComponent2, PRINCIPAL_ADMIN, false); 526 526 // Test if new content is there 527 527 assertEquals(RegistryTestHelper.getXml(testComponent2), … … 536 536 537 537 // Update in db 538 register.update(description, testComponent3 );538 register.update(description, testComponent3, PRINCIPAL_ADMIN, false); 539 539 description = register.getComponentDescription(description.getId()); 540 540 // Test if new values are there -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ProfileDescriptionDaoTest.java
r1332 r1364 4 4 import clarin.cmdi.componentregistry.model.AbstractDescription; 5 5 import clarin.cmdi.componentregistry.model.ProfileDescription; 6 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 6 7 7 8 import org.junit.Before; … … 34 35 return ProfileDescription.createNewDescription(); 35 36 } 37 38 @Override 39 protected String getContentString() { 40 return RegistryTestHelper.getProfileTestContentString(); 41 } 42 36 43 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/filesystem/AdminRegistryTest.java
r1342 r1364 1 1 package clarin.cmdi.componentregistry.impl.filesystem; 2 2 3 import clarin.cmdi.componentregistry.DeleteFailedException; 4 import clarin.cmdi.componentregistry.impl.filesystem.AdminRegistry; 5 import clarin.cmdi.componentregistry.impl.filesystem.ComponentRegistryImpl; 3 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableComponentDescription; 4 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableProfileDescription; 5 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableRegistryUser; 6 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableXmlContent; 7 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.resetDatabase; 6 8 import static org.junit.Assert.assertEquals; 7 9 import static org.junit.Assert.assertTrue; 8 10 import static org.junit.Assert.fail; 9 11 10 import java. io.File;12 import java.security.Principal; 11 13 14 import org.junit.Before; 12 15 import org.junit.Test; 16 import org.junit.runner.RunWith; 17 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.jdbc.core.JdbcTemplate; 19 import org.springframework.test.context.ContextConfiguration; 20 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 21 14 import clarin.cmdi.componentregistry.frontend.FileInfo; 15 import clarin.cmdi.componentregistry.frontend.FileNode; 22 import clarin.cmdi.componentregistry.ComponentRegistry; 23 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 24 import clarin.cmdi.componentregistry.DeleteFailedException; 25 import clarin.cmdi.componentregistry.frontend.CMDItemInfo; 26 import clarin.cmdi.componentregistry.frontend.DisplayDataNode; 16 27 import clarin.cmdi.componentregistry.frontend.SubmitFailedException; 28 import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao; 29 import clarin.cmdi.componentregistry.impl.database.ProfileDescriptionDao; 17 30 import clarin.cmdi.componentregistry.model.ComponentDescription; 18 31 import clarin.cmdi.componentregistry.model.ProfileDescription; 32 import clarin.cmdi.componentregistry.rest.DummyPrincipal; 19 33 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 20 34 21 public class AdminRegistryTest extends ComponentRegistryTestCase { 35 @RunWith(SpringJUnit4ClassRunner.class) 36 @ContextConfiguration(locations = {"/applicationContext-database-impl.xml"}) 37 public 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 } 22 58 23 59 @Test 24 60 public void testForceUpdate() throws Exception { 25 ComponentRegistry Impl 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); 35 71 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); 46 82 47 83 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(); 49 88 fileInfo.setForceUpdate(false); 50 fileInfo.setD isplayNode(new FileNode(new File(getRegistryDir(), "components" + File.separator + compDesc1.getName() + File.separator51 + compDesc1.getName() + ".xml"), false));89 fileInfo.setDataNode(new DisplayDataNode(compDesc1.getName(), false, compDesc1, true)); 90 fileInfo.setContent(content1); 52 91 try { 53 92 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); 54 93 fail(); 55 } catch (SubmitFailedException e) { 56 assertTrue(e.getCause() instanceof DeleteFailedException); 57 } 94 } catch (SubmitFailedException e) {} 58 95 fileInfo.setForceUpdate(true); 59 96 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); //Component needs to be forced because they can be used by other profiles/components … … 74 111 assertEquals(1, testRegistry.getProfileDescriptions().size()); 75 112 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)); 78 114 adminReg.delete(fileInfo, PRINCIPAL_ADMIN); //Profile do not need to be forced they cannot be used by other profiles 79 115 assertEquals(0, testRegistry.getProfileDescriptions().size()); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/filesystem/CMDComponentSpecExpanderTest.java
r1334 r1364 3 3 import static org.junit.Assert.assertEquals; 4 4 5 import java.io.File;6 5 import java.util.List; 7 6 … … 17 16 public class CMDComponentSpecExpanderTest extends ComponentRegistryTestCase{ 18 17 19 private File tmpRegistryDir;20 18 21 19 @Test -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryImplTest.java
r1352 r1364 388 388 389 389 assertEquals(0, registry.getComponentDescriptions().size()); 390 assertNull(registry.getMD Profile(description.getId()));390 assertNull(registry.getMDComponent(description.getId())); 391 391 } 392 392 … … 480 480 assertEquals("MyDescription", desc.getDescription()); 481 481 desc.setDescription("NewDesc"); 482 registry.update(desc, testComponent );482 registry.update(desc, testComponent, PRINCIPAL_ADMIN, false); 483 483 484 484 registry = getTestRegistry(getRegistryDir()); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryTestCase.java
r1333 r1364 1 1 package clarin.cmdi.componentregistry.impl.filesystem; 2 2 3 import clarin.cmdi.componentregistry.ComponentRegistryFactory;4 import clarin.cmdi.componentregistry.Configuration;5 import clarin.cmdi.componentregistry.UserCredentials;6 3 import static org.junit.Assert.assertTrue; 7 4 8 5 import java.io.File; 9 6 import java.security.Principal; 7 import java.util.Arrays; 10 8 import java.util.HashSet; 11 9 import java.util.Set; … … 13 11 import org.apache.commons.io.FileUtils; 14 12 import org.junit.After; 15 16 import clarin.cmdi.componentregistry.rest.DummyPrincipal;17 import java.util.Arrays;18 13 import org.junit.runner.RunWith; 19 14 import org.springframework.beans.factory.annotation.Autowired; … … 21 16 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 22 17 18 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 19 import clarin.cmdi.componentregistry.Configuration; 20 import clarin.cmdi.componentregistry.UserCredentials; 21 import clarin.cmdi.componentregistry.rest.DummyPrincipal; 22 23 23 @RunWith(SpringJUnit4ClassRunner.class) 24 @ContextConfiguration(locations ={"/applicationContext-filesystem-impl.xml"})24 @ContextConfiguration(locations = { "/applicationContext-filesystem-impl.xml" }) 25 25 public abstract class ComponentRegistryTestCase { 26 26 27 27 @Autowired 28 28 protected ComponentRegistryFactory componentRegistryFactory; 29 29 30 30 31 protected File tmpRegistryDir; -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java
r1345 r1364 2 2 3 3 import java.io.ByteArrayInputStream; 4 import java.io.ByteArrayOutputStream; 4 5 import java.io.IOException; 5 6 import java.io.InputStream; … … 8 9 import java.text.ParseException; 9 10 import java.text.SimpleDateFormat; 11 import java.util.regex.Matcher; 12 import java.util.regex.Pattern; 10 13 11 14 import javax.xml.bind.JAXBException; … … 16 19 import clarin.cmdi.componentregistry.model.ComponentDescription; 17 20 import clarin.cmdi.componentregistry.model.ProfileDescription; 18 import java.io.ByteArrayOutputStream;19 import java.util.regex.Matcher;20 import java.util.regex.Pattern;21 21 22 22 /** … … 26 26 public final class RegistryTestHelper { 27 27 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? 29 29 30 30 private RegistryTestHelper() { … … 37 37 public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content) throws ParseException, 38 38 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"))); 41 40 } 42 41 … … 50 49 desc.setId(ComponentRegistry.REGISTRY_ID + id); 51 50 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()); 54 52 testRegistry.register(desc, spec); 55 53 return desc; 56 54 } 57 55 58 public static InputStream getTestProfileContent() {59 return get TestProfileContent("Actor");56 public static String getProfileTestContentString() { 57 return getProfileTestContentString("Actor"); 60 58 } 61 59 62 p ublic static InputStream getTestProfileContent(String name) {60 private static String getProfileTestContentString(String name) { 63 61 String profileContent = ""; 64 62 profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 80 78 profileContent += " </CMD_Component>\n"; 81 79 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()); 83 89 } 84 90 85 91 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()); 88 93 } 89 94 90 95 public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id, String content) throws ParseException, 91 96 JAXBException { 92 return addProfile(testRegistry, id, new ByteArrayInputStream(content. 93 getBytes())); 97 return addProfile(testRegistry, id, new ByteArrayInputStream(content.getBytes())); 94 98 } 95 99 … … 103 107 desc.setId(ComponentRegistry.REGISTRY_ID + id); 104 108 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()); 107 110 testRegistry.register(desc, spec); 108 111 return desc; … … 110 113 111 114 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()); 114 116 } 115 117 … … 148 150 149 151 public static InputStream getComponentTestContent(String componentName) { 150 return new ByteArrayInputStream(getComponentTestContentString(componentName). 151 getBytes()); 152 return new ByteArrayInputStream(getComponentTestContentString(componentName).getBytes()); 152 153 } 153 154 154 155 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()); 157 157 } 158 158 159 159 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()); 162 161 } 163 162 … … 182 181 return matcher.find() && !matcher.find(); //find only one 183 182 } 183 184 184 }
Note: See TracChangeset
for help on using the changeset viewer.