Changeset 5549 for ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/AdminRegistry.java
- Timestamp:
- 08/11/14 16:07:55 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/AdminRegistry.java
r4098 r5549 14 14 import clarin.cmdi.componentregistry.ComponentRegistryException; 15 15 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 16 import clarin.cmdi.componentregistry.ComponentStatus;17 16 import clarin.cmdi.componentregistry.DeleteFailedException; 17 import clarin.cmdi.componentregistry.ItemNotFoundException; 18 18 import clarin.cmdi.componentregistry.MDMarshaller; 19 import clarin.cmdi.componentregistry. OwnerUser;19 import clarin.cmdi.componentregistry.UserCredentials; 20 20 import clarin.cmdi.componentregistry.UserUnauthorizedException; 21 21 import clarin.cmdi.componentregistry.components.CMDComponentSpec; … … 54 54 55 55 public void submitFile(CMDItemInfo info, Principal userPrincipal) 56 throws SubmitFailedException { 56 throws SubmitFailedException, UserUnauthorizedException { 57 if (userPrincipal == null) { 58 LOG.info("Null user principal, nothings is submitted."); 59 return; 60 } 61 57 62 try { 58 63 BaseDescription originalDescription = info.getDataNode() … … 72 77 IOUtils.toInputStream(info.getContent(), "UTF-8"), null); 73 78 checkId(originalDescription.getId(), description.getId()); 74 75 int result = getRegistry(userPrincipal, originalDescription, info) 76 .update(description, spec, userPrincipal, 77 info.isForceUpdate()); 79 ComponentRegistry cr = this.getRegistry(new UserCredentials(userPrincipal)); 80 int result = cr.update(description, spec, info.isForceUpdate()); 78 81 if (result < 0) { 79 82 throw new SubmitFailedException( … … 83 86 throw new SubmitFailedException(e); 84 87 } catch (IOException e) { 88 throw new SubmitFailedException(e); 89 } catch (ItemNotFoundException e) { 85 90 throw new SubmitFailedException(e); 86 91 } … … 109 114 BaseDescription desc = info.getDataNode().getDescription(); 110 115 try { 111 deleteFromRegistry(userPrincipal, desc, info);116 this.deleteFromRegistry(userPrincipal, desc, info); 112 117 LOG.info("Deleted item: " + id); 113 118 } catch (IOException e) { … … 119 124 } catch (ComponentRegistryException e) { 120 125 throw new SubmitFailedException(e); 126 } catch (ItemNotFoundException e) { 127 throw new SubmitFailedException(e); 121 128 } 122 129 … … 125 132 private void deleteFromRegistry(Principal userPrincipal, 126 133 BaseDescription desc, CMDItemInfo info) throws IOException, 127 UserUnauthorizedException, ComponentRegistryException { 128 ComponentRegistry registry = getRegistry(userPrincipal, desc, info); 134 UserUnauthorizedException, ComponentRegistryException, ItemNotFoundException { 135 136 if (userPrincipal == null) { 137 LOG.info("Bnull user principal, nothing is deleted"); 138 return; 139 } 140 141 ComponentRegistry registry = this.getRegistry(new UserCredentials(userPrincipal)); 129 142 LOG.info("Deleting item: " + desc); 130 143 if (desc.isProfile()) { 131 registry.deleteMDProfile(desc.getId() , userPrincipal);144 registry.deleteMDProfile(desc.getId()); 132 145 } else { 133 registry.deleteMDComponent(desc.getId(), userPrincipal, 134 info.isForceUpdate()); 146 registry.deleteMDComponent(desc.getId(), info.isForceUpdate()); 135 147 } 136 148 } 137 149 138 private ComponentRegistry getRegistry(Principal userPrincipal, 139 BaseDescription desc, CMDItemInfo info) { 140 ComponentRegistry registry = componentRegistryFactory 141 .getPublicRegistry(); 142 // TODO: More generic check 143 if (info.getStatus() == ComponentStatus.PRIVATE /* 144 * || info.getStatus() 145 * == ComponentStatus. 146 * DEVELOPMENT 147 */) { 148 registry = componentRegistryFactory.getOtherUserComponentRegistry( 149 userPrincipal, info.getStatus(), 150 new OwnerUser(Integer.parseInt(desc.getUserId()))); 151 } 152 return registry; 153 } 150 private ComponentRegistry getRegistry(UserCredentials credentials) throws UserUnauthorizedException{ 151 return componentRegistryFactory.getBaseRegistry(credentials); 152 } 153 154 154 }
Note: See TracChangeset
for help on using the changeset viewer.