Changeset 1352


Ignore:
Timestamp:
05/23/11 08:34:22 (13 years ago)
Author:
twagoo
Message:

Improved exception throwing and handling. New generic exception class ComponentRegistryException?. DataAccesExceptions? are wrapped in this.

Location:
ComponentRegistry/trunk/ComponentRegistry/src
Files:
1 added
17 edited

Legend:

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

    r1342 r1352  
    1515    public static final String REGISTRY_ID = "clarin.eu:cr1:";
    1616
    17     List<ComponentDescription> getComponentDescriptions();
     17    List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException;
    1818
    19     ComponentDescription getComponentDescription(String id);
     19    ComponentDescription getComponentDescription(String id) throws ComponentRegistryException;
    2020
    21     List<ProfileDescription> getProfileDescriptions();
     21    List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException;
    2222
    23     ProfileDescription getProfileDescription(String id);
     23    ProfileDescription getProfileDescription(String id) throws ComponentRegistryException;
    2424
    25     CMDComponentSpec getMDProfile(String id);
     25    CMDComponentSpec getMDProfile(String id) throws ComponentRegistryException;
    2626
    27     CMDComponentSpec getMDComponent(String id);
     27    CMDComponentSpec getMDComponent(String id) throws ComponentRegistryException;
    2828
    2929    /**
     
    4545    int publish(AbstractDescription desc, CMDComponentSpec spec, Principal principal);
    4646   
    47     void getMDProfileAsXml(String profileId, OutputStream output);
     47    void getMDProfileAsXml(String profileId, OutputStream output) throws ComponentRegistryException;
    4848
    49     void getMDProfileAsXsd(String profileId, OutputStream outputStream);
     49    void getMDProfileAsXsd(String profileId, OutputStream outputStream) throws ComponentRegistryException;
    5050
    51     void getMDComponentAsXml(String componentId, OutputStream output);
     51    void getMDComponentAsXml(String componentId, OutputStream output) throws ComponentRegistryException;
    5252
    53     void getMDComponentAsXsd(String componentId, OutputStream outputStream);
     53    void getMDComponentAsXsd(String componentId, OutputStream outputStream) throws ComponentRegistryException;
    5454
    5555    /**
     
    6161     * @throws DeleteFailedException
    6262     */
    63     void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException, DeleteFailedException;
     63    void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException, ComponentRegistryException, DeleteFailedException;
    6464
    6565    /**
     
    7272     * @throws DeleteFailedException
    7373     */
    74     void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException,
     74    void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException,  ComponentRegistryException, UserUnauthorizedException,
    7575            DeleteFailedException;
    7676
     
    8080     * @return List of ComponentDescriptions of Components that use the given Component.
    8181     */
    82     List<ComponentDescription> getUsageInComponents(String componentId);
     82    List<ComponentDescription> getUsageInComponents(String componentId) throws ComponentRegistryException;
    8383
    8484    /**
     
    8787     * @return List of ProfileDescriptions of Profiles that use the given Component.
    8888     */
    89     List<ProfileDescription> getUsageInProfiles(String componentId);
     89    List<ProfileDescription> getUsageInProfiles(String componentId) throws ComponentRegistryException;
    9090
    9191    /**
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/DeleteFailedException.java

    r472 r1352  
    11package clarin.cmdi.componentregistry;
    22
    3 public class DeleteFailedException extends Exception {
     3public class DeleteFailedException extends ComponentRegistryException {
    44
    55    public DeleteFailedException(String message) {
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/AdminHomePage.java

    r1342 r1352  
    11package clarin.cmdi.componentregistry.frontend;
    22
     3import clarin.cmdi.componentregistry.ComponentRegistryException;
    34import java.io.File;
    45import java.security.Principal;
     
    4849    private ComponentRegistryFactory componentRegistryFactory;
    4950
    50     public AdminHomePage(final PageParameters parameters) {
     51    public AdminHomePage(final PageParameters parameters) throws ComponentRegistryException {
    5152        super(parameters);
    5253        addLinks();
     
    242243    }
    243244
    244     private TreeModel createDBTreeModel() {
     245    private TreeModel createDBTreeModel() throws ComponentRegistryException {
    245246        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new DisplayDataNode("ComponentRegistry", false));
    246247        DefaultMutableTreeNode publicNode = new DefaultMutableTreeNode(new DisplayDataNode("Public", false));
     
    259260    }
    260261
    261     private void add(DefaultMutableTreeNode parent, ComponentRegistry registry) {
     262    private void add(DefaultMutableTreeNode parent, ComponentRegistry registry) throws ComponentRegistryException {
    262263        DefaultMutableTreeNode componentsNode = new DefaultMutableTreeNode(new DisplayDataNode("Components", false));
    263264        parent.add(componentsNode);
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/MassMigratePage.java

    r1342 r1352  
    11package clarin.cmdi.componentregistry.frontend;
    22
     3import clarin.cmdi.componentregistry.ComponentRegistryException;
    34import java.io.ByteArrayOutputStream;
    45import java.io.Serializable;
     
    67import java.util.ArrayList;
    78import java.util.List;
     9import java.util.logging.Level;
    810
    911import javax.xml.bind.JAXBException;
     
    4143@SuppressWarnings("serial")
    4244public class MassMigratePage extends SecureAdminWebPage {
     45
    4346    private final static Logger LOG = LoggerFactory.getLogger(MassMigratePage.class);
    44 
    4547    private FeedbackPanel feedback;
    46 
    4748    @SpringBean(name = "fileRegistryFactory")
    4849    private ComponentRegistryFactoryImpl fileRegistryFactory;
     
    5354    @SpringBean
    5455    private UserDao userDao;
    55 
    5656    private transient UserMapping userMap;
    5757
    5858    public MassMigratePage(final PageParameters pageParameters) {
    59         super(pageParameters);
    60         userMap = fileRegistryFactory.getUserMap();
    61         addLinks();
    62         feedback = new FeedbackPanel("feedback") {
    63             protected Component newMessageDisplayComponent(String id, FeedbackMessage message) {
    64                 Serializable serializable = message.getMessage();
    65                 MultiLineLabel label = new MultiLineLabel(id, (serializable == null) ? "" : serializable.toString());
    66                 label.setEscapeModelStrings(getEscapeModelStrings());
    67                 return label;
    68             }
    69         };
    70         feedback.setOutputMarkupPlaceholderTag(true);
    71         add(feedback);
    72         addMigrationOptions();
     59        super(pageParameters);
     60        userMap = fileRegistryFactory.getUserMap();
     61        addLinks();
     62        feedback = new FeedbackPanel("feedback") {
     63
     64            protected Component newMessageDisplayComponent(String id, FeedbackMessage message) {
     65                Serializable serializable = message.getMessage();
     66                MultiLineLabel label = new MultiLineLabel(id, (serializable == null) ? "" : serializable.toString());
     67                label.setEscapeModelStrings(getEscapeModelStrings());
     68                return label;
     69            }
     70        };
     71        feedback.setOutputMarkupPlaceholderTag(true);
     72        add(feedback);
     73        addMigrationOptions();
    7374    }
    7475
    7576    private void addLinks() {
    76         add(new Label("linksMessage", "Do some mass migration or go to:"));
    77         add(new Link("home") {
    78             @Override
    79             public void onClick() {
    80                 setResponsePage(AdminHomePage.class);
    81             }
    82         });
     77        add(new Label("linksMessage", "Do some mass migration or go to:"));
     78        add(new Link("home") {
     79
     80            @Override
     81            public void onClick() {
     82                setResponsePage(AdminHomePage.class);
     83            }
     84        });
    8385    }
    8486
    8587    private void addMigrationOptions() {
    86         add(new Label("migrate1Label", "Click here to start the migration of the file storage into the database."));
    87         add(new IndicatingAjaxLink("migrate1") {
    88             public void onClick(final AjaxRequestTarget target) {
    89                 if (target != null) {
    90                     target.addComponent(feedback);
    91                 }
    92                 startMigration();
    93             }
    94         });
     88        add(new Label("migrate1Label", "Click here to start the migration of the file storage into the database."));
     89        add(new IndicatingAjaxLink("migrate1") {
     90
     91            public void onClick(final AjaxRequestTarget target) {
     92                if (target != null) {
     93                    target.addComponent(feedback);
     94                }
     95                startMigration();
     96            }
     97        });
    9598    }
    9699
    97100    private void startMigration() {
    98         info("Start Migration users...");
    99         List<User> users = userMap.getUsers();
    100         for (User user : users) {
    101             userDao.insertUser(user);
    102         }
    103         info("Start Migration descriptions and content...");
    104         List<ComponentRegistry> registries = new ArrayList<ComponentRegistry>();
    105         registries.add(fileRegistryFactory.getPublicRegistry());
    106         registries.addAll(fileRegistryFactory.getAllUserRegistries());
    107         for (ComponentRegistry registry : registries) {
    108             migrateDescriptions(registry.getComponentDescriptions(), registry, componentDescriptionDao);
    109             migrateDescriptions(registry.getProfileDescriptions(), registry, profileDescriptionDao);
    110         }
    111         info("End Migration.");
     101        info("Start Migration users...");
     102        List<User> users = userMap.getUsers();
     103        for (User user : users) {
     104            userDao.insertUser(user);
     105        }
     106        info("Start Migration descriptions and content...");
     107        List<ComponentRegistry> registries = new ArrayList<ComponentRegistry>();
     108        registries.add(fileRegistryFactory.getPublicRegistry());
     109        registries.addAll(fileRegistryFactory.getAllUserRegistries());
     110        for (ComponentRegistry registry : registries) {
     111            try {
     112                migrateDescriptions(registry.getComponentDescriptions(), registry, componentDescriptionDao);
     113                migrateDescriptions(registry.getProfileDescriptions(), registry, profileDescriptionDao);
     114            } catch (ComponentRegistryException e) {
     115                LOG.error("Error in migration, check the logs!", e);
     116                info("Error cannot retrieve descriptions from registry " + registry.getName());
     117            }
     118        }
     119        info("End Migration.");
    112120    }
    113121
    114122    private void migrateDescriptions(List<? extends AbstractDescription> descs, ComponentRegistry registry, AbstractDescriptionDao descDao) {
    115         int migrateCount = 0;
    116         for (AbstractDescription description : descs) {
    117             try {
    118                 User user = userDao.getByPrincipalName(userMap.findUser(description.getUserId()).getPrincipalName());
    119                 descDao.insertDescription(description, getContent(description, registry), registry.isPublic(), user.getId());
    120             } catch (Exception e) {
    121                 LOG.error("Error in migration, check the logs!", e);
    122                 info("Error cannot migrate " + description.getId());
    123             }
    124             migrateCount++;
    125         }
    126         LOG.info(registry.getName() + " migrated: " + migrateCount + " out of " + descs.size() + " descs");
     123        int migrateCount = 0;
     124        for (AbstractDescription description : descs) {
     125            try {
     126                User user = userDao.getByPrincipalName(userMap.findUser(description.getUserId()).getPrincipalName());
     127                descDao.insertDescription(description, getContent(description, registry), registry.isPublic(), user.getId());
     128            } catch (Exception e) {
     129                LOG.error("Error in migration, check the logs!", e);
     130                info("Error cannot migrate " + description.getId());
     131            }
     132            migrateCount++;
     133        }
     134        LOG.info(registry.getName() + " migrated: " + migrateCount + " out of " + descs.size() + " descs");
    127135    }
    128136
    129137    private String getContent(AbstractDescription description, ComponentRegistry registry) throws UnsupportedEncodingException,
    130             JAXBException {
    131         ByteArrayOutputStream out = new ByteArrayOutputStream();
    132         CMDComponentSpec spec = null;
    133         if (description.isProfile()) {
    134             spec = registry.getMDProfile(description.getId());
    135         } else {
    136             spec = registry.getMDComponent(description.getId());
    137         }
    138         MDMarshaller.marshal(spec, out);
    139         return out.toString();
     138            JAXBException,
     139            ComponentRegistryException {
     140        ByteArrayOutputStream out = new ByteArrayOutputStream();
     141        CMDComponentSpec spec = null;
     142        if (description.isProfile()) {
     143            spec = registry.getMDProfile(description.getId());
     144        } else {
     145            spec = registry.getMDComponent(description.getId());
     146        }
     147        MDMarshaller.marshal(spec, out);
     148        return out.toString();
    140149    }
    141 
    142150}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/StatisticsPage.java

    r1334 r1352  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
     4import clarin.cmdi.componentregistry.ComponentRegistryException;
    45import clarin.cmdi.componentregistry.impl.filesystem.ComponentRegistryFactoryImpl;
    56import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     
    3334    }
    3435
    35     public StatisticsPage(final PageParameters pageParameters) throws IOException {
     36    public StatisticsPage(final PageParameters pageParameters) throws IOException, ComponentRegistryException {
    3637        super(pageParameters);
    3738        addLinks();
     
    3940    }
    4041
    41     private void DisplayStatistics() {
     42    private void DisplayStatistics() throws ComponentRegistryException {
    4243        List<ProfileDescription> profileList = registry.getProfileDescriptions();
    4344        RepeatingView repeating = new RepeatingView("repeating");
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java

    r1343 r1352  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
     4import clarin.cmdi.componentregistry.ComponentRegistryException;
    45import clarin.cmdi.componentregistry.DeleteFailedException;
    56import clarin.cmdi.componentregistry.MDMarshaller;
     
    2627 * @author Twan Goosen <twan.goosen@mpi.nl>
    2728 */
    28 public abstract class ComponentRegistryImplBase implements ComponentRegistry{
    29         private final static Logger LOG = LoggerFactory.getLogger(ComponentRegistryImplBase.class);
     29public abstract class ComponentRegistryImplBase implements ComponentRegistry {
     30
     31    private final static Logger LOG = LoggerFactory.getLogger(ComponentRegistryImplBase.class);
    3032
    3133    @Override
    32     public List<ComponentDescription> getUsageInComponents(String componentId) {
     34    public List<ComponentDescription> getUsageInComponents(String componentId) throws ComponentRegistryException {
    3335        List<ComponentDescription> result = new ArrayList<ComponentDescription>();
    3436        List<ComponentDescription> descs = getComponentDescriptions();
     
    4345
    4446    @Override
    45     public List<ProfileDescription> getUsageInProfiles(String componentId) {
     47    public List<ProfileDescription> getUsageInProfiles(String componentId) throws ComponentRegistryException {
    4648        List<ProfileDescription> result = new ArrayList<ProfileDescription>();
    4749        for (ProfileDescription profileDescription : getProfileDescriptions()) {
     
    5557
    5658    /* HELPER METHODS */
    57 
    5859    protected static String stripRegistryId(String id) {
    59         return StringUtils.removeStart(id, ComponentRegistry.REGISTRY_ID);
     60        return StringUtils.removeStart(id, ComponentRegistry.REGISTRY_ID);
    6061    }
    6162
    6263    protected static void enrichSpecHeader(CMDComponentSpec spec, AbstractDescription description) {
    63         Header header = spec.getHeader();
    64         header.setID(description.getId());
    65         if (StringUtils.isEmpty(header.getName())) {
    66             header.setName(description.getName());
    67         }
    68         if (StringUtils.isEmpty(header.getDescription())) {
    69             header.setDescription(description.getDescription());
    70         }
     64        Header header = spec.getHeader();
     65        header.setID(description.getId());
     66        if (StringUtils.isEmpty(header.getName())) {
     67            header.setName(description.getName());
     68        }
     69        if (StringUtils.isEmpty(header.getDescription())) {
     70            header.setDescription(description.getDescription());
     71        }
    7172    }
    7273
    7374    protected static boolean findComponentId(String componentId, List<CMDComponentType> componentReferences) {
    74         for (CMDComponentType cmdComponent : componentReferences) {
    75             if (componentId.equals(cmdComponent.getComponentId())) {
    76                 return true;
    77             } else if (findComponentId(componentId, cmdComponent.getCMDComponent())) {
    78                 return true;
    79             }
    80         }
    81         return false;
     75        for (CMDComponentType cmdComponent : componentReferences) {
     76            if (componentId.equals(cmdComponent.getComponentId())) {
     77                return true;
     78            } else if (findComponentId(componentId, cmdComponent.getCMDComponent())) {
     79                return true;
     80            }
     81        }
     82        return false;
    8283    }
    8384
    8485    protected static void writeXsd(CMDComponentSpec expandedSpec, OutputStream outputStream) {
    85         MDMarshaller.generateXsd(expandedSpec, outputStream);
     86        MDMarshaller.generateXsd(expandedSpec, outputStream);
    8687    }
    8788
    8889    protected static void writeXml(CMDComponentSpec spec, OutputStream outputStream) {
    89         try {
    90             MDMarshaller.marshal(spec, outputStream);
    91         } catch (UnsupportedEncodingException e) {
    92             LOG.error("Error in encoding: ", e);
    93         } catch (JAXBException e) {
    94             LOG.error("Cannot marshall spec: " + spec, e);
    95         }
     90        try {
     91            MDMarshaller.marshal(spec, outputStream);
     92        } catch (UnsupportedEncodingException e) {
     93            LOG.error("Error in encoding: ", e);
     94        } catch (JAXBException e) {
     95            LOG.error("Cannot marshall spec: " + spec, e);
     96        }
    9697    }
    9798
    98     protected void checkStillUsed(String componentId) throws DeleteFailedException {
    99         List<ProfileDescription> profiles = getUsageInProfiles(componentId);
    100         List<ComponentDescription> components = getUsageInComponents(componentId);
    101         if (!profiles.isEmpty() || !components.isEmpty()) {
    102             throw new DeleteFailedException(createStillInUseMessage(profiles, components));
    103         }
     99    protected void checkStillUsed(String componentId) throws DeleteFailedException, ComponentRegistryException {
     100        List<ProfileDescription> profiles = getUsageInProfiles(componentId);
     101        List<ComponentDescription> components = getUsageInComponents(componentId);
     102        if (!profiles.isEmpty() || !components.isEmpty()) {
     103            throw new DeleteFailedException(createStillInUseMessage(profiles, components));
     104        }
    104105    }
    105106
    106107    private String createStillInUseMessage(List<ProfileDescription> profiles, List<ComponentDescription> components) {
    107         StringBuilder result = new StringBuilder();
    108         if (!profiles.isEmpty()) {
    109             result.append("Still used by the following profiles: \n");
    110             for (ProfileDescription profileDescription : profiles) {
    111                 result.append(" - ").append(profileDescription.getName()).append("\n");
    112             }
    113         }
    114         if (!components.isEmpty()) {
    115             result.append("Still used by the following components: \n");
    116             for (ComponentDescription componentDescription : components) {
    117                 result.append(" - ").append(componentDescription.getName()).append("\n");
    118             }
    119         }
    120         result.append("Try to change above mentioned references first.");
    121         return result.toString();
     108        StringBuilder result = new StringBuilder();
     109        if (!profiles.isEmpty()) {
     110            result.append("Still used by the following profiles: \n");
     111            for (ProfileDescription profileDescription : profiles) {
     112                result.append(" - ").append(profileDescription.getName()).append("\n");
     113            }
     114        }
     115        if (!components.isEmpty()) {
     116            result.append("Still used by the following components: \n");
     117            for (ComponentDescription componentDescription : components) {
     118                result.append(" - ").append(componentDescription.getName()).append("\n");
     119            }
     120        }
     121        result.append("Try to change above mentioned references first.");
     122        return result.toString();
    122123    }
    123124
    124125    /* UNIMPLEMENTED INTERFACE METHODS */
     126    @Override
     127    public abstract List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException;
    125128
    126129    @Override
    127     public abstract List<ComponentDescription> getComponentDescriptions();
     130    public abstract ComponentDescription getComponentDescription(String id) throws ComponentRegistryException;
    128131
    129132    @Override
    130     public abstract ComponentDescription getComponentDescription(String id);
     133    public abstract List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException;
    131134
    132135    @Override
    133     public abstract List<ProfileDescription> getProfileDescriptions();
     136    public abstract ProfileDescription getProfileDescription(String id) throws ComponentRegistryException;
    134137
    135138    @Override
    136     public abstract ProfileDescription getProfileDescription(String id);
     139    public abstract CMDComponentSpec getMDProfile(String id) throws ComponentRegistryException;
    137140
    138141    @Override
    139     public abstract CMDComponentSpec getMDProfile(String id);
    140 
    141     @Override
    142     public abstract CMDComponentSpec getMDComponent(String id);
     142    public abstract CMDComponentSpec getMDComponent(String id) throws ComponentRegistryException;
    143143
    144144    @Override
     
    146146
    147147    @Override
    148     public abstract  int update(AbstractDescription description, CMDComponentSpec spec);
     148    public abstract int update(AbstractDescription description, CMDComponentSpec spec);
    149149
    150150    @Override
    151     public abstract  int publish(AbstractDescription desc, CMDComponentSpec spec, Principal principal);
     151    public abstract int publish(AbstractDescription desc, CMDComponentSpec spec, Principal principal);
    152152
    153153    @Override
    154     public abstract  void getMDProfileAsXml(String profileId, OutputStream output);
     154    public abstract void getMDProfileAsXml(String profileId, OutputStream output) throws ComponentRegistryException;
    155155
    156156    @Override
    157     public abstract  void getMDProfileAsXsd(String profileId, OutputStream outputStream);
     157    public abstract void getMDProfileAsXsd(String profileId, OutputStream outputStream) throws ComponentRegistryException;
    158158
    159159    @Override
    160     public abstract  void getMDComponentAsXml(String componentId, OutputStream output);
     160    public abstract void getMDComponentAsXml(String componentId, OutputStream output) throws ComponentRegistryException;
    161161
    162162    @Override
    163     public abstract  void getMDComponentAsXsd(String componentId, OutputStream outputStream);
     163    public abstract void getMDComponentAsXsd(String componentId, OutputStream outputStream) throws ComponentRegistryException;
    164164
    165165    @Override
    166     public abstract  void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException, DeleteFailedException;
     166    public abstract void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException, DeleteFailedException, ComponentRegistryException;
    167167
    168168    @Override
    169     public abstract  void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException, DeleteFailedException;
     169    public abstract void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException, DeleteFailedException, ComponentRegistryException;
    170170
    171171    @Override
    172     public abstract  boolean isPublic();
    173 
     172    public abstract boolean isPublic();
    174173}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r1346 r1352  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
     4import clarin.cmdi.componentregistry.ComponentRegistryException;
    45import clarin.cmdi.componentregistry.Configuration;
    56import clarin.cmdi.componentregistry.DeleteFailedException;
     
    4041    private Number userId;
    4142    @Autowired
     43    private Configuration configuration;
     44    @Autowired
    4245    private ProfileDescriptionDao profileDescriptionDao;
    4346    @Autowired
     
    4649    private UserDao userDao;
    4750    @Autowired
    48     Configuration configuration;
    49     @Autowired
    5051    @Qualifier("componentsCache")
    51     CMDComponentSpecCache componentsCache;
     52    private CMDComponentSpecCache componentsCache;
    5253    @Autowired
    5354    @Qualifier("profilesCache")
    54     CMDComponentSpecCache profilesCache;
     55    private CMDComponentSpecCache profilesCache;
    5556
    5657    /**
     
    7172
    7273    @Override
    73     public List<ProfileDescription> getProfileDescriptions() {
     74    public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException {
    7475        try {
    7576            if (isPublic()) {
     
    7980            }
    8081        } catch (DataAccessException ex) {
    81             LOG.error("Database access error while trying to get profile descriptions", ex);
    82             throw ex;
    83         }
    84     }
    85 
    86     @Override
    87     public ProfileDescription getProfileDescription(String id) {
     82            throw new ComponentRegistryException("Database access error while trying to get profile descriptions", ex);
     83        }
     84    }
     85
     86    @Override
     87    public ProfileDescription getProfileDescription(String id) throws ComponentRegistryException {
    8888        try {
    8989            return profileDescriptionDao.getByCmdId(id, getUserId());
    9090        } catch (DataAccessException ex) {
    91             LOG.error("Database access error while trying to get profile description", ex);
    92             throw ex;
    93         }
    94     }
    95 
    96     @Override
    97     public List<ComponentDescription> getComponentDescriptions() {
     91            throw new ComponentRegistryException("Database access error while trying to get profile description", ex);
     92        }
     93    }
     94
     95    @Override
     96    public List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException {
    9897        try {
    9998            if (isPublic()) {
     
    103102            }
    104103        } catch (DataAccessException ex) {
    105             LOG.error("Database access error while trying to get component descriptions", ex);
    106             throw ex;
    107         }
    108     }
    109 
    110     @Override
    111     public ComponentDescription getComponentDescription(String id) {
     104            throw new ComponentRegistryException("Database access error while trying to get component descriptions", ex);
     105        }
     106    }
     107
     108    @Override
     109    public ComponentDescription getComponentDescription(String id) throws ComponentRegistryException {
    112110        try {
    113111            return componentDescriptionDao.getByCmdId(id, getUserId());
    114112        } catch (DataAccessException ex) {
    115             LOG.error("Database access error while trying to get component description", ex);
    116             throw ex;
    117         }
    118     }
    119 
    120     @Override
    121     public CMDComponentSpec getMDProfile(String id) {
     113            throw new ComponentRegistryException("Database access error while trying to get component description", ex);
     114        }
     115    }
     116
     117    @Override
     118    public CMDComponentSpec getMDProfile(String id) throws ComponentRegistryException {
    122119        if (inWorkspace(profileDescriptionDao, id)) {
    123120            CMDComponentSpec result = profilesCache.get(id);
     
    128125            return result;
    129126        } else {
     127            // May exist, but not in this workspace
    130128            return null;
    131129        }
    132130    }
    133131
    134     public CMDComponentSpec getUncachedMDProfile(String id) {
     132    public CMDComponentSpec getUncachedMDProfile(String id) throws ComponentRegistryException {
    135133        try {
    136134            return getUncachedMDComponent(id, profileDescriptionDao);
    137135        } catch (DataAccessException ex) {
    138             LOG.error("Database access error while trying to get profile", ex);
    139             throw ex;
    140         }
    141     }
    142 
    143     @Override
    144     public CMDComponentSpec getMDComponent(String id) {
     136            throw new ComponentRegistryException("Database access error while trying to get profile", ex);
     137        }
     138    }
     139
     140    @Override
     141    public CMDComponentSpec getMDComponent(String id) throws ComponentRegistryException {
    145142        if (inWorkspace(componentDescriptionDao, id)) {
    146143            CMDComponentSpec result = componentsCache.get(id);
     
    155152    }
    156153
    157     public CMDComponentSpec getUncachedMDComponent(String id) {
     154    public CMDComponentSpec getUncachedMDComponent(String id) throws ComponentRegistryException {
    158155        try {
    159156            return getUncachedMDComponent(id, componentDescriptionDao);
    160157        } catch (DataAccessException ex) {
    161             LOG.error("Database access error while trying to get component", ex);
    162             throw ex;
     158            throw new ComponentRegistryException("Database access error while trying to get component", ex);
    163159        }
    164160    }
     
    174170            invalidateCache(description);
    175171            return 0;
     172        } catch (DataAccessException ex) {
     173            LOG.error("Database error while registering component", ex);
     174            return -1;
    176175        } catch (JAXBException ex) {
    177             LOG.error(null, ex);
     176            LOG.error("Error while registering component", ex);
     177            return -2;
    178178        } catch (UnsupportedEncodingException ex) {
    179             LOG.error(null, ex);
    180         } catch (DataAccessException ex) {
    181             LOG.error("Database error while registering component", ex);
    182         }
    183         return -1;
     179            LOG.error("Error while registering component", ex);
     180            return -3;
     181        }
    184182    }
    185183
     
    216214            return 0;
    217215        } catch (DataAccessException ex) {
    218             LOG.error(null, ex);
     216            LOG.error("Database error while updating component", ex);
    219217            return -1;
     218        } catch (JAXBException ex) {
     219            LOG.error("Error while updating component", ex);
     220            return -2;
     221        } catch (UnsupportedEncodingException ex) {
     222            LOG.error("Error while updating component", ex);
     223            return -3;
    220224        } catch (IllegalArgumentException ex) {
    221             LOG.error(null, ex);
    222             return -2;
    223         } catch (JAXBException ex) {
    224             LOG.error(null, ex);
    225             return -3;
    226         } catch (UnsupportedEncodingException ex) {
    227             LOG.error(null, ex);
     225            LOG.error("Error while updating component", ex);
    228226            return -4;
    229227        }
     
    235233        AbstractDescriptionDao<?> dao = getDaoForDescription(desc);
    236234        if (!isPublic()) { //if already in public workspace there is nothing todo
     235            desc.setHref(AbstractDescription.createPublicHref(desc.getHref()));
     236            Number id = getIdForDescription(desc);
    237237            try {
    238                 desc.setHref(AbstractDescription.createPublicHref(desc.getHref()));
    239                 Number id = getIdForDescription(desc);
    240238                // Update description & content
    241239                dao.updateDescription(id, desc, componentSpecToString(spec));
    242240                // Set to public
    243241                dao.setPublished(id, true);
    244             } catch (Exception e) {
    245                 LOG.error("Delete failed:", e);
    246                 result = -1;
     242            } catch (DataAccessException ex) {
     243                LOG.error("Database error while updating component", ex);
     244                return -1;
     245            } catch (JAXBException ex) {
     246                LOG.error("Error while updating component", ex);
     247                return -2;
     248            } catch (UnsupportedEncodingException ex) {
     249                LOG.error("Error while updating component", ex);
     250                return -3;
    247251            }
    248252        }
     
    252256    @Override
    253257    public void getMDProfileAsXml(String profileId, OutputStream output) {
    254         CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.
    255                 expandProfile(profileId, this);
     258        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandProfile(profileId, this);
    256259        writeXml(expandedSpec, output);
    257260    }
     
    259262    @Override
    260263    public void getMDProfileAsXsd(String profileId, OutputStream outputStream) {
    261         CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.
    262                 expandProfile(profileId, this);
     264        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandProfile(profileId, this);
    263265        writeXsd(expandedSpec, outputStream);
    264266    }
     
    266268    @Override
    267269    public void getMDComponentAsXml(String componentId, OutputStream output) {
    268         CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.
    269                 expandComponent(componentId, this);
     270        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandComponent(componentId, this);
    270271        writeXml(expandedSpec, output);
    271272    }
     
    273274    @Override
    274275    public void getMDComponentAsXsd(String componentId, OutputStream outputStream) {
    275         CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.
    276                 expandComponent(componentId, this);
     276        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.expandComponent(componentId, this);
    277277        writeXsd(expandedSpec, outputStream);
    278278    }
    279279
    280280    @Override
    281     public void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException, DeleteFailedException {
    282         try {
    283             ProfileDescription desc = getProfileDescription(profileId);
    284             if (desc != null) {
     281    public void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException, DeleteFailedException, ComponentRegistryException {
     282        ProfileDescription desc = getProfileDescription(profileId);
     283        if (desc != null) {
     284            try {
    285285                checkAuthorisation(desc, principal);
    286286                checkAge(desc, principal);
    287287                profileDescriptionDao.setDeleted(getIdForDescription(desc));
    288288                invalidateCache(desc);
    289             }
    290         } catch (DataAccessException ex) {
    291             LOG.error("Database access error while trying to delete profile", ex);
    292             throw ex;
    293         }
    294 
    295     }
    296 
    297     @Override
    298     public void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException, DeleteFailedException {
    299         try {
    300             ComponentDescription desc = componentDescriptionDao.getByCmdId(componentId);
    301             if (desc != null) {
     289            } catch (DataAccessException ex) {
     290                throw new DeleteFailedException("Database access error while trying to delete profile", ex);
     291            }
     292        }
     293    }
     294
     295    @Override
     296    public void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException, DeleteFailedException, ComponentRegistryException {
     297        ComponentDescription desc = componentDescriptionDao.getByCmdId(componentId);
     298        if (desc != null) {
     299            try {
    302300                checkAuthorisation(desc, principal);
    303301                checkAge(desc, principal);
     
    308306                componentDescriptionDao.setDeleted(getIdForDescription(desc));
    309307                invalidateCache(desc);
    310             }
    311         } catch (DataAccessException ex) {
    312             LOG.error("Database access error while trying to delete component", ex);
    313             throw ex;
     308            } catch (DataAccessException ex) {
     309                throw new DeleteFailedException("Database access error while trying to delete component", ex);
     310            }
    314311        }
    315312    }
     
    386383            try {
    387384                InputStream is = new ByteArrayInputStream(xml.getBytes());
    388                 return MDMarshaller.unmarshal(CMDComponentSpec.class, is, MDMarshaller.
    389                         getCMDComponentSchema());
     385                return MDMarshaller.unmarshal(CMDComponentSpec.class, is, MDMarshaller.getCMDComponentSchema());
    390386            } catch (JAXBException ex) {
    391387                LOG.error(null, ex);
     
    398394        if (!isOwnerOfDescription(desc, principal.getName())
    399395                && !configuration.isAdminUser(principal)) {
    400             throw new UserUnauthorizedException("Unauthorized operation user '" + principal.
    401                     getName()
    402                     + "' is not the creator (nor an administrator) of the " + (desc.
    403                     isProfile() ? "profile" : "component") + "(" + desc
     396            throw new UserUnauthorizedException("Unauthorized operation user '" + principal.getName()
     397                    + "' is not the creator (nor an administrator) of the " + (desc.isProfile() ? "profile" : "component") + "(" + desc
    404398                    + ").");
    405399        }
     
    415409        if (isPublic() && !configuration.isAdminUser(principal)) {
    416410            try {
    417                 Date regDate = AbstractDescription.getDate(desc.
    418                         getRegistrationDate());
     411                Date regDate = AbstractDescription.getDate(desc.getRegistrationDate());
    419412                Calendar calendar = Calendar.getInstance();
    420413                calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
     
    431424    }
    432425
    433 
    434426    private boolean inWorkspace(AbstractDescriptionDao<?> dao, String cmdId) {
    435427        if (isPublic()) {
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/filesystem/AdminRegistry.java

    r1342 r1352  
    11package clarin.cmdi.componentregistry.impl.filesystem;
    22
     3import clarin.cmdi.componentregistry.ComponentRegistryException;
    34import java.io.File;
    45import java.io.FileInputStream;
     
    2728
    2829public class AdminRegistry {
     30
    2931    private final static Logger LOG = LoggerFactory.getLogger(AdminRegistry.class);
    3032
    3133    public void submitFile(FileInfo fileInfo, Principal userPrincipal) throws SubmitFailedException {
    32         try {
    33             File file = getFile(fileInfo);
    34             if (fileInfo.getDisplayNode().isDeleted()) {
    35                 //already deleted file
    36                 FileUtils.writeStringToFile(file, fileInfo.getText(), "UTF-8");
    37             } else {
    38                 //Description or cmdSpec file.
    39                 String name = fileInfo.getName();
    40                 String id = ComponentRegistry.REGISTRY_ID + getFile(fileInfo).getParentFile().getName();
    41                 AbstractDescription originalDescription = getDescription(fileInfo);
    42                 CMDComponentSpec originalSpec = getSpec(fileInfo);
    43                 AbstractDescription description = null;
    44                 CMDComponentSpec spec = null;
    45                 if (ComponentRegistryImpl.DESCRIPTION_FILE_NAME.equals(name)) {
    46                     if (getFile(fileInfo).getParentFile().getName().startsWith("c_")) {
    47                         description = MDMarshaller.unmarshal(ComponentDescription.class,
    48                                 IOUtils.toInputStream(fileInfo.getText(), "UTF-8"), null);
    49                     } else {
    50                         description = MDMarshaller.unmarshal(ProfileDescription.class, IOUtils.toInputStream(fileInfo.getText(), "UTF-8"),
    51                                 null);
    52                     }
    53                     checkId(id, description.getId());
    54                     spec = originalSpec;
    55                 } else {
    56                     spec = MDMarshaller.unmarshal(CMDComponentSpec.class, IOUtils.toInputStream(fileInfo.getText(), "UTF-8"), MDMarshaller
    57                             .getCMDComponentSchema());
    58                     checkId(id, spec.getHeader().getID());
    59                     description = originalDescription;
    60                 }
    61                 deleteFromRegistry(userPrincipal, originalDescription, fileInfo);
    62                 int result = submitToRegistry(description, spec, userPrincipal, fileInfo);
    63                 if (result == 0) {
    64                     //submit is successful so now really delete the old one, we cannot have that around anymore.
    65                     ComponentRegistryImpl registry = (ComponentRegistryImpl) getRegistry(userPrincipal, originalDescription, fileInfo);
    66                     registry.emptyFromTrashcan(originalDescription);
    67                 } else {
    68                     throw new SubmitFailedException("Problem occured while registering, please check the tomcat logs for errors. "
    69                             + "Original files are removed already you can find them "
    70                             + "in the deleted section of the registry. You have to put that back manually.");
    71                 }
    72             }
    73         } catch (JAXBException e) {
    74             throw new SubmitFailedException(e);
    75         } catch (IOException e) {
    76             throw new SubmitFailedException(e);
    77         } catch (UserUnauthorizedException e) {
    78             throw new SubmitFailedException(e);
    79         } catch (DeleteFailedException e) {
    80             throw new SubmitFailedException(e);
    81         }
     34        try {
     35            File file = getFile(fileInfo);
     36            if (fileInfo.getDisplayNode().isDeleted()) {
     37                //already deleted file
     38                FileUtils.writeStringToFile(file, fileInfo.getText(), "UTF-8");
     39            } 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                }
     73            }
     74        } catch (JAXBException e) {
     75            throw new SubmitFailedException(e);
     76        } catch (IOException e) {
     77            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        }
    8285
    8386    }
    8487
    8588    private void checkId(String id, String id2) throws SubmitFailedException {
    86         if (id == null || id2 == null || !id.equals(id2)) {
    87             throw new SubmitFailedException("Id's do not match up, you cannot edit id's: id1=" + id + ", id2=" + id2);
    88         }
     89        if (id == null || id2 == null || !id.equals(id2)) {
     90            throw new SubmitFailedException("Id's do not match up, you cannot edit id's: id1=" + id + ", id2=" + id2);
     91        }
    8992    }
    9093
    9194    public void undelete(FileInfo fileInfo, Principal userPrincipal) throws SubmitFailedException {
    92         String id = fileInfo.getName();
    93         AbstractDescription desc = getDescription(fileInfo);
    94         try {
    95             CMDComponentSpec spec = getSpec(fileInfo);
    96             int result = submitToRegistry(desc, spec, userPrincipal, fileInfo);
    97             if (result == 0) {
    98                 FileUtils.deleteDirectory(getFile(fileInfo));
    99                 LOG.info("Undeleted item: " + id);
    100             } else {
    101                 throw new SubmitFailedException("Problem occured while registering, please check the tomcat logs for errors.");
    102             }
    103         } catch (IOException e) {
    104             throw new SubmitFailedException(e);
    105         } catch (JAXBException e) {
    106             throw new SubmitFailedException(e);
    107         }
     95        String id = fileInfo.getName();
     96        AbstractDescription desc = getDescription(fileInfo);
     97        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);
     103            } else {
     104                throw new SubmitFailedException("Problem occured while registering, please check the tomcat logs for errors.");
     105            }
     106        } catch (IOException e) {
     107            throw new SubmitFailedException(e);
     108        } catch (JAXBException e) {
     109            throw new SubmitFailedException(e);
     110        }
    108111
    109112    }
    110113
    111114    public void delete(FileInfo fileInfo, Principal userPrincipal) throws SubmitFailedException {
    112         String id = fileInfo.getName();
    113         AbstractDescription desc = getDescription(fileInfo);
    114         try {
    115             deleteFromRegistry(userPrincipal, desc, fileInfo);
    116             LOG.info("Deleted item: " + id);
    117         } catch (IOException e) {
    118             throw new SubmitFailedException(e);
    119         } catch (UserUnauthorizedException e) {
    120             throw new SubmitFailedException(e);
    121         } catch (DeleteFailedException e) {
    122             throw new SubmitFailedException(e);
    123         }
     115        String id = fileInfo.getName();
     116        AbstractDescription desc = getDescription(fileInfo);
     117        try {
     118            deleteFromRegistry(userPrincipal, desc, fileInfo);
     119            LOG.info("Deleted item: " + id);
     120        } catch (IOException e) {
     121            throw new SubmitFailedException(e);
     122        } catch (UserUnauthorizedException e) {
     123            throw new SubmitFailedException(e);
     124        } catch (DeleteFailedException e) {
     125            throw new SubmitFailedException(e);
     126        } catch (ComponentRegistryException e) {
     127            throw new SubmitFailedException(e);
     128        }
    124129
    125130    }
    126131
    127132    private int submitToRegistry(AbstractDescription description, CMDComponentSpec spec, Principal userPrincipal, FileInfo fileInfo) {
    128         ComponentRegistry registry = getRegistry(userPrincipal, description, fileInfo);
    129         if (spec.isIsProfile()) {
    130             return registry.register((ProfileDescription) description, spec);
    131         } else {
    132             return registry.register((ComponentDescription) description, spec);
    133         }
     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        }
    134139
    135140    }
    136141
    137142    private void deleteFromRegistry(Principal userPrincipal, AbstractDescription desc, FileInfo fileInfo) throws IOException,
    138             UserUnauthorizedException, DeleteFailedException {
    139         ComponentRegistry registry = getRegistry(userPrincipal, desc, fileInfo);
    140         LOG.info("Deleting item: " + desc);
    141         if (desc.isProfile()) {
    142             registry.deleteMDProfile(desc.getId(), userPrincipal);
    143         } else {
    144             registry.deleteMDComponent(desc.getId(), userPrincipal, fileInfo.isForceUpdate());
    145         }
     143            UserUnauthorizedException, DeleteFailedException, ComponentRegistryException {
     144        ComponentRegistry registry = getRegistry(userPrincipal, desc, fileInfo);
     145        LOG.info("Deleting item: " + desc);
     146        if (desc.isProfile()) {
     147            registry.deleteMDProfile(desc.getId(), userPrincipal);
     148        } else {
     149            registry.deleteMDComponent(desc.getId(), userPrincipal, fileInfo.isForceUpdate());
     150        }
    146151    }
    147152
    148153    private ComponentRegistry getRegistry(Principal userPrincipal, AbstractDescription desc, FileInfo fileInfo) {
    149         ComponentRegistry registry = ComponentRegistryFactoryImpl.getInstance().getPublicRegistry();
    150         if (fileInfo.isInUserWorkSpace()) {
    151             registry = ComponentRegistryFactoryImpl.getInstance().getOtherUserComponentRegistry(userPrincipal, desc.getUserId());
    152         }
    153         return registry;
     154        ComponentRegistry registry = ComponentRegistryFactoryImpl.getInstance().getPublicRegistry();
     155        if (fileInfo.isInUserWorkSpace()) {
     156            registry = ComponentRegistryFactoryImpl.getInstance().getOtherUserComponentRegistry(userPrincipal, desc.getUserId());
     157        }
     158        return registry;
    154159    }
    155160
    156161    private CMDComponentSpec getSpec(FileInfo fileInfo) throws FileNotFoundException, JAXBException {
    157         File parent = getFile(fileInfo);
    158         if (!parent.isDirectory()) {
    159             parent = parent.getParentFile();
    160         }
    161         File file = new File(parent, parent.getName() + ".xml");
    162         CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, new FileInputStream(file), MDMarshaller
    163                 .getCMDComponentSchema());
    164         return spec;
     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;
    165169    }
    166170
    167171    private AbstractDescription getDescription(FileInfo fileInfo) {
    168         File parent = getFile(fileInfo);
    169         if (!parent.isDirectory()) {
    170             parent = parent.getParentFile();
    171         }
    172         File descFile = new File(parent, ComponentRegistryImpl.DESCRIPTION_FILE_NAME);
    173         Class<? extends AbstractDescription> clazz = fileInfo.isComponent() ? ComponentDescription.class : ProfileDescription.class;
    174         AbstractDescription result = MDMarshaller.unmarshal(clazz, descFile, null);
    175         return result;
     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;
    176180    }
    177181
    178182    private File getFile(FileInfo fileInfo) {
    179         FileNode fileNode = (FileNode) fileInfo.getDisplayNode();
    180         return fileNode.getFile();
     183        FileNode fileNode = (FileNode) fileInfo.getDisplayNode();
     184        return fileNode.getFile();
    181185    }
    182 
    183186}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryImpl.java

    r1346 r1352  
    33import clarin.cmdi.componentregistry.impl.ComponentRegistryImplBase;
    44import clarin.cmdi.componentregistry.ComponentRegistry;
     5import clarin.cmdi.componentregistry.ComponentRegistryException;
    56import clarin.cmdi.componentregistry.Configuration;
    67import clarin.cmdi.componentregistry.DeleteFailedException;
     
    356357    @Override
    357358    public void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException,
    358             UserUnauthorizedException, DeleteFailedException {
     359            UserUnauthorizedException, DeleteFailedException, ComponentRegistryException {
    359360        ComponentDescription desc = componentDescriptions.get(componentId);
    360361        if (desc != null) {
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentClosure.java

    r1089 r1352  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
     4import clarin.cmdi.componentregistry.ComponentRegistryException;
    45import clarin.cmdi.componentregistry.model.ComponentDescription;
    56
     
    78
    89    @Override
    9     public ComponentDescription getDescription(ComponentRegistry registry, String id) {
     10    public ComponentDescription getDescription(ComponentRegistry registry, String id) throws ComponentRegistryException {
    1011        return registry.getComponentDescription(id);
    1112    }
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1345 r1352  
    3333
    3434import clarin.cmdi.componentregistry.ComponentRegistry;
     35import clarin.cmdi.componentregistry.ComponentRegistryException;
    3536import clarin.cmdi.componentregistry.ComponentRegistryFactory;
    3637import clarin.cmdi.componentregistry.DeleteFailedException;
     
    6263    public static final String DOMAIN_FORM_FIELD = "domainName";
    6364    public static final String USERSPACE_PARAM = "userspace";
    64 
    65 
    66     @Inject(value="componentRegistryFactory")
     65    @Inject(value = "componentRegistryFactory")
    6766    private ComponentRegistryFactory componentRegistryFactory;
    6867
    6968    private ComponentRegistry getRegistry(boolean userspace) {
    70         Principal userPrincipal = security.getUserPrincipal();
    71         UserCredentials userCredentials = getUserCredentials(userPrincipal);
    72         return getRegistry(userspace, userCredentials);
     69        Principal userPrincipal = security.getUserPrincipal();
     70        UserCredentials userCredentials = getUserCredentials(userPrincipal);
     71        return getRegistry(userspace, userCredentials);
    7372    }
    7473
    7574    private ComponentRegistry getRegistry(boolean userspace, UserCredentials userCredentials) {
    76         return componentRegistryFactory.getComponentRegistry(userspace, userCredentials);
     75        return componentRegistryFactory.getComponentRegistry(userspace, userCredentials);
    7776    }
    7877
    7978    private Principal checkAndGetUserPrincipal() {
    80         Principal principal = security.getUserPrincipal();
    81         if (principal == null) {
    82             throw new IllegalArgumentException("no user principal found.");
    83         }
    84         return principal;
     79        Principal principal = security.getUserPrincipal();
     80        if (principal == null) {
     81            throw new IllegalArgumentException("no user principal found.");
     82        }
     83        return principal;
    8584    }
    8685
    8786    private UserCredentials getUserCredentials(Principal userPrincipal) {
    88         UserCredentials userCredentials = null;
    89         if (userPrincipal != null) {
    90             userCredentials = new UserCredentials(userPrincipal);
    91         }
    92         return userCredentials;
     87        UserCredentials userCredentials = null;
     88        if (userPrincipal != null) {
     89            userCredentials = new UserCredentials(userPrincipal);
     90        }
     91        return userCredentials;
    9392    }
    9493
     
    9695    @Path("/components")
    9796    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    98     public List<ComponentDescription> getRegisteredComponents(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    99         long start = System.currentTimeMillis();
    100         List<ComponentDescription> components = getRegistry(userspace).getComponentDescriptions();
    101         LOG.info("Releasing " + components.size() + " registered components into the world (" + (System.currentTimeMillis() - start)
    102                 + " millisecs)");
    103         return components;
     97    public List<ComponentDescription> getRegisteredComponents(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     98        long start = System.currentTimeMillis();
     99        List<ComponentDescription> components = getRegistry(userspace).getComponentDescriptions();
     100        LOG.info("Releasing " + components.size() + " registered components into the world (" + (System.currentTimeMillis() - start)
     101                + " millisecs)");
     102        return components;
    104103    }
    105104
     
    107106    @Path("/profiles")
    108107    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    109     public List<ProfileDescription> getRegisteredProfiles(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    110         long start = System.currentTimeMillis();
    111         List<ProfileDescription> profiles = getRegistry(userspace).getProfileDescriptions();
    112         LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start)
    113                 + " millisecs)");
    114         return profiles;
     108    public List<ProfileDescription> getRegisteredProfiles(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     109        long start = System.currentTimeMillis();
     110        List<ProfileDescription> profiles = getRegistry(userspace).getProfileDescriptions();
     111        LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start)
     112                + " millisecs)");
     113        return profiles;
    115114    }
    116115
     
    119118    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    120119    public CMDComponentSpec getRegisteredComponent(@PathParam("componentId") String componentId,
    121             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    122         LOG.info("Component with id: " + componentId + " is requested.");
    123         return getRegistry(userspace).getMDComponent(componentId);
     120            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     121        LOG.info("Component with id: " + componentId + " is requested.");
     122        return getRegistry(userspace).getMDComponent(componentId);
    124123    }
    125124
     
    128127    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
    129128    public Response getRegisteredComponentRawType(@PathParam("componentId") final String componentId, @PathParam("rawType") String rawType) {
    130         LOG.info("Component with id: " + componentId + " and rawType:" + rawType + " is requested.");
    131         StreamingOutput result = null;
    132         final ComponentRegistry registry = findRegistry(componentId, new ComponentClosure());
    133         if (registry == null) {
    134             return Response.status(Status.NOT_FOUND).entity("Id: " + componentId + " is not registered, cannot create data.").build();
    135         }
    136         ComponentDescription desc = registry.getComponentDescription(componentId);
    137         checkAndThrowDescription(desc, componentId);
    138         String fileName = desc.getName() + "." + rawType;
    139         if ("xml".equalsIgnoreCase(rawType)) {
    140             result = new StreamingOutput() {
    141 
    142                 public void write(OutputStream output) throws IOException, WebApplicationException {
    143                     registry.getMDComponentAsXml(componentId, output);
    144                 }
    145             };
    146         } else if ("xsd".equalsIgnoreCase(rawType)) {
    147             result = new StreamingOutput() {
    148 
    149                 public void write(OutputStream output) throws IOException, WebApplicationException {
    150                     registry.getMDComponentAsXsd(componentId, output);
    151                 }
    152             };
    153         } else {
    154             throw new WebApplicationException(Response.serverError().entity(
    155                     "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
    156         }
    157         return createDownloadResponse(result, fileName);
    158     }
    159 
    160     public ComponentRegistry findRegistry(String id, RegistryClosure<? extends AbstractDescription> clos) {
    161         AbstractDescription desc = null;
    162         ComponentRegistry result = getRegistry(false);
    163         desc = clos.getDescription(result, id);
    164         if (desc == null) {
    165             List<ComponentRegistry> userRegs = componentRegistryFactory.getAllUserRegistries();
    166             for (ComponentRegistry reg : userRegs) {
    167                 desc = clos.getDescription(reg, id);
    168                 if (desc != null) {
    169                     result = reg;
    170                     break;
    171                 }
    172             }
    173         }
    174         return result;
     129        LOG.info("Component with id: " + componentId + " and rawType:" + rawType + " is requested.");
     130        StreamingOutput result = null;
     131        try {
     132            final ComponentRegistry registry = findRegistry(componentId, new ComponentClosure());
     133            if (registry == null) {
     134                return Response.status(Status.NOT_FOUND).entity("Id: " + componentId + " is not registered, cannot create data.").build();
     135            }
     136            ComponentDescription desc = registry.getComponentDescription(componentId);
     137            checkAndThrowDescription(desc, componentId);
     138            String fileName = desc.getName() + "." + rawType;
     139            if ("xml".equalsIgnoreCase(rawType)) {
     140                result = new StreamingOutput() {
     141
     142                    @Override
     143                    public void write(OutputStream output) throws IOException, WebApplicationException {
     144                        try {
     145                            registry.getMDComponentAsXml(componentId, output);
     146                        } catch (ComponentRegistryException e) {
     147                            LOG.info("Could not retrieve component", e);
     148                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     149                        }
     150                    }
     151                };
     152            } else if ("xsd".equalsIgnoreCase(rawType)) {
     153                result = new StreamingOutput() {
     154
     155                    @Override
     156                    public void write(OutputStream output) throws IOException, WebApplicationException {
     157                        try {
     158                            registry.getMDComponentAsXsd(componentId, output);
     159                        } catch (ComponentRegistryException e) {
     160                            LOG.info("Could not retrieve component", e);
     161                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     162                        }
     163
     164                    }
     165                };
     166            } else {
     167                throw new WebApplicationException(Response.serverError().entity(
     168                        "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
     169            }
     170            return createDownloadResponse(result, fileName);
     171        } catch (ComponentRegistryException e) {
     172            LOG.info("Could not retrieve component", e);
     173            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     174        }
     175    }
     176
     177    public ComponentRegistry findRegistry(String id, RegistryClosure<? extends AbstractDescription> clos) throws ComponentRegistryException {
     178        AbstractDescription desc = null;
     179        ComponentRegistry result = getRegistry(false);
     180        desc = clos.getDescription(result, id);
     181        if (desc == null) {
     182            List<ComponentRegistry> userRegs = componentRegistryFactory.getAllUserRegistries();
     183            for (ComponentRegistry reg : userRegs) {
     184                desc = clos.getDescription(reg, id);
     185                if (desc != null) {
     186                    result = reg;
     187                    break;
     188                }
     189            }
     190        }
     191        return result;
    175192    }
    176193
     
    179196    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    180197    public CMDComponentSpec getRegisteredProfile(@PathParam("profileId") String profileId,
    181             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    182         LOG.info("Profile with id: " + profileId + " is requested.");
    183         return getRegistry(userspace).getMDProfile(profileId);
     198            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     199        LOG.info("Profile with id: " + profileId + " is requested.");
     200        return getRegistry(userspace).getMDProfile(profileId);
    184201    }
    185202
     
    195212    @Path("/profiles/{profileId}")
    196213    public Response manipulateRegisteredProfile(@PathParam("profileId") String profileId, @FormParam("method") String method,
    197             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    198         if ("delete".equalsIgnoreCase(method)) {
    199             return deleteRegisteredProfile(profileId, userspace);
    200         } else {
    201             return Response.ok().build();
    202         }
     214            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     215        if ("delete".equalsIgnoreCase(method)) {
     216            return deleteRegisteredProfile(profileId, userspace);
     217        } else {
     218            return Response.ok().build();
     219        }
    203220    }
    204221
     
    207224    @Consumes("multipart/form-data")
    208225    public Response publishRegisteredProfile(@PathParam("profileId") String profileId, @FormDataParam(DATA_FORM_FIELD) InputStream input,
    209             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
    210             @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    211         Principal principal = checkAndGetUserPrincipal();
    212         ProfileDescription desc = getRegistry(true).getProfileDescription(profileId);
    213         if (desc != null) {
    214             updateDescription(desc, name, description, domainName, group);
    215             return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
    216         } else {
    217             LOG.error("Update of nonexistent id (" + profileId + ") failed.");
    218             return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
    219         }
     226            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     227            @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     228        Principal principal = checkAndGetUserPrincipal();
     229        try {
     230            ProfileDescription desc = getRegistry(true).getProfileDescription(profileId);
     231            if (desc != null) {
     232                updateDescription(desc, name, description, domainName, group);
     233                return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
     234            } else {
     235                LOG.error("Update of nonexistent id (" + profileId + ") failed.");
     236                return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
     237            }
     238        } catch (ComponentRegistryException e) {
     239            LOG.info("Could not retrieve component", e);
     240            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     241        }
    220242    }
    221243
     
    224246    @Consumes("multipart/form-data")
    225247    public Response updateRegisteredProfile(@PathParam("profileId") String profileId,
    226             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
    227             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
    228             @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    229         Principal principal = checkAndGetUserPrincipal();
    230         UserCredentials userCredentials = getUserCredentials(principal);
    231         ProfileDescription desc = getRegistry(userspace).getProfileDescription(profileId);
    232         if (desc != null) {
    233             updateDescription(desc, name, description, domainName, group);
    234             return register(input, desc, userCredentials, userspace, new UpdateAction());
    235         } else {
    236             LOG.error("Update of nonexistent id (" + profileId + ") failed.");
    237             return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
    238         }
     248            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
     249            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     250            @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     251        Principal principal = checkAndGetUserPrincipal();
     252        UserCredentials userCredentials = getUserCredentials(principal);
     253        try {
     254            ProfileDescription desc = getRegistry(userspace).getProfileDescription(profileId);
     255            if (desc != null) {
     256                updateDescription(desc, name, description, domainName, group);
     257                return register(input, desc, userCredentials, userspace, new UpdateAction());
     258            } else {
     259                LOG.error("Update of nonexistent id (" + profileId + ") failed.");
     260                return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
     261            }
     262        } catch (ComponentRegistryException e) {
     263            LOG.info("Could not retrieve component", e);
     264            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     265        }
    239266    }
    240267
     
    250277    @Path("/components/{componentId}")
    251278    public Response manipulateRegisteredComponent(@PathParam("componentId") String componentId, @FormParam("method") String method,
    252             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    253         if ("delete".equalsIgnoreCase(method)) {
    254             return deleteRegisteredComponent(componentId, userspace);
    255         } else {
    256             return Response.ok().build();
    257         }
     279            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     280        if ("delete".equalsIgnoreCase(method)) {
     281            return deleteRegisteredComponent(componentId, userspace);
     282        } else {
     283            return Response.ok().build();
     284        }
    258285    }
    259286
     
    262289    @Consumes("multipart/form-data")
    263290    public Response publishRegisteredComponent(@PathParam("componentId") String componentId,
    264             @FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    265             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
    266             @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    267         Principal principal = checkAndGetUserPrincipal();
    268         ComponentDescription desc = getRegistry(true).getComponentDescription(componentId);
    269         if (desc != null) {
    270             updateDescription(desc, name, description, domainName, group);
    271             return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
    272         } else {
    273             LOG.error("Update of nonexistent id (" + componentId + ") failed.");
    274             return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
    275         }
     291            @FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
     292            @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
     293            @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     294        Principal principal = checkAndGetUserPrincipal();
     295        try {
     296            ComponentDescription desc = getRegistry(true).getComponentDescription(componentId);
     297            if (desc != null) {
     298                updateDescription(desc, name, description, domainName, group);
     299                return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
     300            } else {
     301                LOG.error("Update of nonexistent id (" + componentId + ") failed.");
     302                return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
     303            }
     304        } catch (ComponentRegistryException e) {
     305            LOG.info("Could not retrieve component", e);
     306            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     307        }
    276308    }
    277309
     
    280312    @Consumes("multipart/form-data")
    281313    public Response updateRegisteredComponent(@PathParam("componentId") String componentId,
    282             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
    283             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
    284             @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    285         Principal principal = checkAndGetUserPrincipal();
    286         ComponentDescription desc = getRegistry(userspace).getComponentDescription(componentId);
    287         if (desc != null) {
    288             updateDescription(desc, name, description, domainName, group);
    289             return register(input, desc, getUserCredentials(principal), userspace, new UpdateAction());
    290         } else {
    291             LOG.error("Update of nonexistent id (" + componentId + ") failed.");
    292             return Response.serverError().entity("Invalid id, cannot update nonexistent component").build();
    293         }
     314            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
     315            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     316            @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     317        Principal principal = checkAndGetUserPrincipal();
     318        try {
     319            ComponentDescription desc = getRegistry(userspace).getComponentDescription(componentId);
     320            if (desc != null) {
     321                updateDescription(desc, name, description, domainName, group);
     322                return register(input, desc, getUserCredentials(principal), userspace, new UpdateAction());
     323            } else {
     324                LOG.error("Update of nonexistent id (" + componentId + ") failed.");
     325                return Response.serverError().entity("Invalid id, cannot update nonexistent component").build();
     326            }
     327        } catch (ComponentRegistryException e) {
     328            LOG.info("Could not retrieve component", e);
     329            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     330        }
    294331    }
    295332
    296333    private void updateDescription(AbstractDescription desc, String name, String description, String domainName, String group) {
    297         desc.setName(name);
    298         desc.setDescription(description);
    299         desc.setDomainName(domainName);
    300         desc.setGroupName(group);
    301         desc.setRegistrationDate(AbstractDescription.createNewDate());
     334        desc.setName(name);
     335        desc.setDescription(description);
     336        desc.setDomainName(domainName);
     337        desc.setGroupName(group);
     338        desc.setRegistrationDate(AbstractDescription.createNewDate());
    302339    }
    303340
     
    305342    @Path("/components/{componentId}")
    306343    public Response deleteRegisteredComponent(@PathParam("componentId") String componentId,
    307             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    308         Principal principal = checkAndGetUserPrincipal();
    309         ComponentRegistry registry = getRegistry(userspace);
    310         LOG.info("Component with id: " + componentId + " set for deletion.");
    311         try {
    312             registry.deleteMDComponent(componentId, principal, false);
    313         } catch (DeleteFailedException e) {
    314             LOG.info("Component with id: " + componentId + " deletion failed.", e);
    315             return Response.status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
    316         } catch (IOException e) {
    317             LOG.info("Component with id: " + componentId + " deletion failed.", e);
    318             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    319         } catch (UserUnauthorizedException e) {
    320             LOG.info("Component with id: " + componentId + " deletion failed: " + e.getMessage());
    321             return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    322         }
    323         LOG.info("Component with id: " + componentId + " deleted.");
    324         return Response.ok().build();
     344            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     345        Principal principal = checkAndGetUserPrincipal();
     346        ComponentRegistry registry = getRegistry(userspace);
     347        LOG.info("Component with id: " + componentId + " set for deletion.");
     348        try {
     349            registry.deleteMDComponent(componentId, principal, false);
     350        } catch (DeleteFailedException e) {
     351            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     352            return Response.status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     353        } catch (ComponentRegistryException e) {
     354            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     355            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     356        } catch (IOException e) {
     357            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     358            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     359        } catch (UserUnauthorizedException e) {
     360            LOG.info("Component with id: " + componentId + " deletion failed: " + e.getMessage());
     361            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     362        }
     363        LOG.info("Component with id: " + componentId + " deleted.");
     364        return Response.ok().build();
    325365    }
    326366
     
    328368    @Path("/profiles/{profileId}")
    329369    public Response deleteRegisteredProfile(@PathParam("profileId") String profileId,
    330             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    331         Principal principal = checkAndGetUserPrincipal();
    332         LOG.info("Profile with id: " + profileId + " set for deletion.");
    333         try {
    334             getRegistry(userspace).deleteMDProfile(profileId, principal);
    335         } catch (DeleteFailedException e) {
    336             LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
    337             return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
    338         } catch (IOException e) {
    339             LOG.info("Profile with id: " + profileId + " deletion failed.", e);
    340             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    341         } catch (UserUnauthorizedException e) {
    342             LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
    343             return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    344         }
    345         LOG.info("Profile with id: " + profileId + " deleted.");
    346         return Response.ok().build();
     370            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     371        Principal principal = checkAndGetUserPrincipal();
     372        LOG.info("Profile with id: " + profileId + " set for deletion.");
     373        try {
     374            getRegistry(userspace).deleteMDProfile(profileId, principal);
     375        } catch (DeleteFailedException e) {
     376            LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
     377            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     378        } catch (ComponentRegistryException e) {
     379            LOG.info("Could not retrieve component", e);
     380            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     381        } catch (IOException e) {
     382            LOG.info("Profile with id: " + profileId + " deletion failed.", e);
     383            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     384        } catch (UserUnauthorizedException e) {
     385            LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
     386            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     387        }
     388        LOG.info("Profile with id: " + profileId + " deleted.");
     389        return Response.ok().build();
    347390    }
    348391
     
    351394    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
    352395    public Response getRegisteredProfileRawType(@PathParam("profileId") final String profileId, @PathParam("rawType") String rawType) {
    353         LOG.info("Profile with id: " + profileId + " and rawType:" + rawType + " is requested.");
    354         StreamingOutput result = null;
    355         final ComponentRegistry registry = findRegistry(profileId, new ProfileClosure());
    356         if (registry == null) {
    357             return Response.status(Status.NOT_FOUND).entity("Id: " + profileId + " is not registered, cannot create data.").build();
    358         }
    359         ProfileDescription desc = registry.getProfileDescription(profileId);
    360         checkAndThrowDescription(desc, profileId);
    361         String fileName = desc.getName() + "." + rawType;
    362 
    363         if ("xml".equalsIgnoreCase(rawType)) {
    364             result = new StreamingOutput() {
    365 
    366                 public void write(OutputStream output) throws IOException, WebApplicationException {
    367                     registry.getMDProfileAsXml(profileId, output);
    368                 }
    369             };
    370         } else if ("xsd".equalsIgnoreCase(rawType)) {
    371             result = new StreamingOutput() {
    372 
    373                 public void write(OutputStream output) throws IOException, WebApplicationException {
    374                     registry.getMDProfileAsXsd(profileId, output);
    375                 }
    376             };
    377         } else {
    378             throw new WebApplicationException(Response.serverError().entity(
    379                     "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
    380         }
    381         return createDownloadResponse(result, fileName);
     396        LOG.info("Profile with id: " + profileId + " and rawType:" + rawType + " is requested.");
     397        StreamingOutput result = null;
     398        try {
     399            final ComponentRegistry registry = findRegistry(profileId, new ProfileClosure());
     400            if (registry == null) {
     401                return Response.status(Status.NOT_FOUND).entity("Id: " + profileId + " is not registered, cannot create data.").build();
     402            }
     403            ProfileDescription desc = registry.getProfileDescription(profileId);
     404            checkAndThrowDescription(desc, profileId);
     405            String fileName = desc.getName() + "." + rawType;
     406
     407            if ("xml".equalsIgnoreCase(rawType)) {
     408                result = new StreamingOutput() {
     409
     410                    @Override
     411                    public void write(OutputStream output) throws IOException, WebApplicationException {
     412                        try {
     413                            registry.getMDProfileAsXml(profileId, output);
     414                        } catch (ComponentRegistryException e) {
     415                            LOG.info("Could not retrieve component", e);
     416                            throw new WebApplicationException(Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     417                        }
     418                    }
     419                };
     420            } else if ("xsd".equalsIgnoreCase(rawType)) {
     421                result = new StreamingOutput() {
     422
     423                    @Override
     424                    public void write(OutputStream output) throws IOException, WebApplicationException {
     425                        try {
     426                            registry.getMDProfileAsXsd(profileId, output);
     427                        } catch (ComponentRegistryException e) {
     428                            LOG.info("Could not retrieve component", e);
     429                            throw new WebApplicationException(Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     430                        }
     431                    }
     432                };
     433            } else {
     434                throw new WebApplicationException(Response.serverError().entity(
     435                        "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
     436            }
     437            return createDownloadResponse(result, fileName);
     438        } catch (ComponentRegistryException e) {
     439            LOG.info("Could not retrieve component", e);
     440            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     441        }
    382442    }
    383443
    384444    private void checkAndThrowDescription(AbstractDescription desc, String id) {
    385         if (desc == null) {
    386             throw new WebApplicationException(Response.serverError().entity("Incorrect id:" + id + "cannot handle request").build());
    387         }
     445        if (desc == null) {
     446            throw new WebApplicationException(Response.serverError().entity("Incorrect id:" + id + "cannot handle request").build());
     447        }
    388448    }
    389449
    390450    private Response createDownloadResponse(StreamingOutput result, String fileName) {
    391         //Making response so it triggers browsers native save as dialog.
    392         Response response = Response.ok().type("application/x-download").header("Content-Disposition",
    393                 "attachment; filename=\"" + fileName + "\"").entity(result).build();
    394         return response;
     451        //Making response so it triggers browsers native save as dialog.
     452        Response response = Response.ok().type("application/x-download").header("Content-Disposition",
     453                "attachment; filename=\"" + fileName + "\"").entity(result).build();
     454        return response;
    395455
    396456    }
     
    401461    @Consumes("multipart/form-data")
    402462    public Response registerProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    403             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName,
    404             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    405         Principal principal = checkAndGetUserPrincipal();
    406         UserCredentials userCredentials = getUserCredentials(principal);
    407         ProfileDescription desc = createNewProfileDescription();
    408         desc.setCreatorName(userCredentials.getDisplayName());
     463            @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName,
     464            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     465        Principal principal = checkAndGetUserPrincipal();
     466        UserCredentials userCredentials = getUserCredentials(principal);
     467        ProfileDescription desc = createNewProfileDescription();
     468        desc.setCreatorName(userCredentials.getDisplayName());
    409469        desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
    410         desc.setName(name);
    411         desc.setDescription(description);
    412         desc.setGroupName(group);
    413         desc.setDomainName(domainName);
    414         LOG.info("Trying to register Profile: " + desc);
    415         return register(input, desc, userCredentials, userspace, new NewAction());
     470        desc.setName(name);
     471        desc.setDescription(description);
     472        desc.setGroupName(group);
     473        desc.setDomainName(domainName);
     474        LOG.info("Trying to register Profile: " + desc);
     475        return register(input, desc, userCredentials, userspace, new NewAction());
    416476    }
    417477
     
    421481    @Consumes("multipart/form-data")
    422482    public Response registerComponent(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    423             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
    424             @FormDataParam(DOMAIN_FORM_FIELD) String domainName, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    425         Principal principal = checkAndGetUserPrincipal();
    426         UserCredentials userCredentials = getUserCredentials(principal);
    427         ComponentDescription desc = createNewComponentDescription();
    428         desc.setCreatorName(userCredentials.getDisplayName());
    429         desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
    430         desc.setName(name);
    431         desc.setDescription(description);
    432         desc.setGroupName(group);
    433         desc.setDomainName(domainName);
    434         LOG.info("Trying to register Component: " + desc);
    435         return register(input, desc, userCredentials, userspace, new NewAction());
     483            @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
     484            @FormDataParam(DOMAIN_FORM_FIELD) String domainName, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     485        Principal principal = checkAndGetUserPrincipal();
     486        UserCredentials userCredentials = getUserCredentials(principal);
     487        ComponentDescription desc = createNewComponentDescription();
     488        desc.setCreatorName(userCredentials.getDisplayName());
     489        desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
     490        desc.setName(name);
     491        desc.setDescription(description);
     492        desc.setGroupName(group);
     493        desc.setDomainName(domainName);
     494        LOG.info("Trying to register Component: " + desc);
     495        return register(input, desc, userCredentials, userspace, new NewAction());
    436496    }
    437497
     
    440500    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    441501    public Response pingSession() {
    442         boolean stillActive = false;
    443         Principal userPrincipal = security.getUserPrincipal();
    444         LOG.info("ping by user: " + (userPrincipal == null ? "null" : userPrincipal.getName()));
    445         if (request != null) {
    446             if (userPrincipal != null && !ComponentRegistryFactory.ANONYMOUS_USER.equals(userPrincipal.getName())) {
    447                 stillActive = !((HttpServletRequest) request).getSession().isNew();
    448             }
    449         }
    450         return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build();
     502        boolean stillActive = false;
     503        Principal userPrincipal = security.getUserPrincipal();
     504        LOG.info("ping by user: " + (userPrincipal == null ? "null" : userPrincipal.getName()));
     505        if (request != null) {
     506            if (userPrincipal != null && !ComponentRegistryFactory.ANONYMOUS_USER.equals(userPrincipal.getName())) {
     507                stillActive = !((HttpServletRequest) request).getSession().isNew();
     508            }
     509        }
     510        return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build();
    451511    }
    452512
    453513    private Response register(InputStream input, AbstractDescription desc, UserCredentials userCredentials, boolean userspace,
    454             RegisterAction action) {
    455         try {
    456             ComponentRegistry registry = getRegistry(userspace, userCredentials);
    457             DescriptionValidator descriptionValidator = new DescriptionValidator(desc);
    458             MDValidator validator = new MDValidator(input, desc, registry, getRegistry(true), componentRegistryFactory.getPublicRegistry());
    459             RegisterResponse response = new RegisterResponse();
    460             response.setIsInUserSpace(userspace);
    461             validate(response, descriptionValidator, validator);
    462             if (response.getErrors().isEmpty()) {
    463                 CMDComponentSpec spec = validator.getCMDComponentSpec();
    464                 int returnCode = action.execute(desc, spec, response, registry);
    465                 if (returnCode == 0) {
    466                     response.setRegistered(true);
    467                     response.setDescription(desc);
    468                 } else {
    469                     response.setRegistered(false);
    470                     response.addError("Unable to register at this moment. Internal server error.");
    471                 }
    472             } else {
    473                 LOG.info("Registration failed with validation errors:" + Arrays.toString(response.getErrors().toArray()));
    474                 response.setRegistered(false);
    475             }
    476             response.setIsProfile(desc.isProfile());
    477             return Response.ok(response).build();
    478         } finally {
    479             try {
    480                 input.close();//either we read the input or there was an exception, we need to close it.
    481             } catch (IOException e) {
    482                 LOG.error("Error when closing inputstream: ", e);
    483             }
    484         }
     514            RegisterAction action) {
     515        try {
     516            ComponentRegistry registry = getRegistry(userspace, userCredentials);
     517            DescriptionValidator descriptionValidator = new DescriptionValidator(desc);
     518            MDValidator validator = new MDValidator(input, desc, registry, getRegistry(true), componentRegistryFactory.getPublicRegistry());
     519            RegisterResponse response = new RegisterResponse();
     520            response.setIsInUserSpace(userspace);
     521            validate(response, descriptionValidator, validator);
     522            if (response.getErrors().isEmpty()) {
     523                CMDComponentSpec spec = validator.getCMDComponentSpec();
     524                int returnCode = action.execute(desc, spec, response, registry);
     525                if (returnCode == 0) {
     526                    response.setRegistered(true);
     527                    response.setDescription(desc);
     528                } else {
     529                    response.setRegistered(false);
     530                    response.addError("Unable to register at this moment. Internal server error.");
     531                }
     532            } else {
     533                LOG.info("Registration failed with validation errors:" + Arrays.toString(response.getErrors().toArray()));
     534                response.setRegistered(false);
     535            }
     536            response.setIsProfile(desc.isProfile());
     537            return Response.ok(response).build();
     538        } finally {
     539            try {
     540                input.close();//either we read the input or there was an exception, we need to close it.
     541            } catch (IOException e) {
     542                LOG.error("Error when closing inputstream: ", e);
     543            }
     544        }
    485545    }
    486546
    487547    private ComponentDescription createNewComponentDescription() {
    488         ComponentDescription desc = ComponentDescription.createNewDescription();
    489         desc.setHref(createXlink(desc.getId()));
    490         return desc;
     548        ComponentDescription desc = ComponentDescription.createNewDescription();
     549        desc.setHref(createXlink(desc.getId()));
     550        return desc;
    491551    }
    492552
    493553    private ProfileDescription createNewProfileDescription() {
    494         ProfileDescription desc = ProfileDescription.createNewDescription();
    495         desc.setHref(createXlink(desc.getId()));
    496         return desc;
     554        ProfileDescription desc = ProfileDescription.createNewDescription();
     555        desc.setHref(createXlink(desc.getId()));
     556        return desc;
    497557    }
    498558
    499559    private String createXlink(String id) {
    500         URI uri = uriInfo.getRequestUriBuilder().path(id).build();
    501         return uri.toString();
     560        URI uri = uriInfo.getRequestUriBuilder().path(id).build();
     561        return uri.toString();
    502562    }
    503563
    504564    private void validate(RegisterResponse response, Validator... validators) {
    505         for (Validator validator : validators) {
    506             if (!validator.validate()) {
    507                 for (String error : validator.getErrorMessages()) {
    508                     response.addError(error);
    509                 }
    510             }
    511         }
     565        for (Validator validator : validators) {
     566            if (!validator.validate()) {
     567                for (String error : validator.getErrorMessages()) {
     568                    response.addError(error);
     569                }
     570            }
     571        }
    512572    }
    513573
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/MDValidator.java

    r1282 r1352  
    88
    99import clarin.cmdi.componentregistry.ComponentRegistry;
     10import clarin.cmdi.componentregistry.ComponentRegistryException;
    1011import clarin.cmdi.componentregistry.MDMarshaller;
    1112import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     
    2021    static final String PARSE_ERROR = "Error in validation input file. Error is: ";
    2122    static final String COMPONENT_NOT_PUBLICLY_REGISTERED_ERROR = "referenced component cannot be found in the published components: ";
     23    static final String COMPONENT_REGISTRY_EXCEPTION_ERROR = "An exception occurred while accessing the component registry: ";
    2224
    2325    private List<String> errorMessages = new ArrayList<String>();
     
    6062        }
    6163        if (errorMessages.isEmpty()) {
    62             validateComponents(spec.getCMDComponent());
     64            try {
     65                validateComponents(spec.getCMDComponent());
     66            } catch (ComponentRegistryException e) {
     67                errorMessages.add(COMPONENT_REGISTRY_EXCEPTION_ERROR + e);
     68            }
    6369        }
    6470        return errorMessages.isEmpty();
    6571    }
    6672
    67     private void validateComponents(List<CMDComponentType> cmdComponents) {
     73    private void validateComponents(List<CMDComponentType> cmdComponents) throws ComponentRegistryException {
    6874        for (CMDComponentType cmdComponentType : cmdComponents) {
    6975            validateDescribedComponents(cmdComponentType);
     
    7278    }
    7379
    74     private void validateDescribedComponents(CMDComponentType cmdComponentType) {
     80    private void validateDescribedComponents(CMDComponentType cmdComponentType) throws ComponentRegistryException {
    7581        if (isDefinedInSeparateFile(cmdComponentType)) {
    7682            String id = cmdComponentType.getComponentId();
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ProfileClosure.java

    r1089 r1352  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
     4import clarin.cmdi.componentregistry.ComponentRegistryException;
    45import clarin.cmdi.componentregistry.model.ProfileDescription;
    56
     
    78
    89    @Override
    9     public ProfileDescription getDescription(ComponentRegistry registry, String id) {
     10    public ProfileDescription getDescription(ComponentRegistry registry, String id) throws ComponentRegistryException {
    1011        return registry.getProfileDescription(id);
    1112    }
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/RegistryClosure.java

    r1089 r1352  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
     4import clarin.cmdi.componentregistry.ComponentRegistryException;
    45import clarin.cmdi.componentregistry.model.AbstractDescription;
    56
    67public interface RegistryClosure<T extends AbstractDescription> {
    78   
    8     T getDescription(ComponentRegistry registry, String id);
     9    T getDescription(ComponentRegistry registry, String id) throws ComponentRegistryException;
    910
    1011
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImplTest.java

    r1346 r1352  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
     4import clarin.cmdi.componentregistry.ComponentRegistryException;
    45import clarin.cmdi.componentregistry.DeleteFailedException;
    56import clarin.cmdi.componentregistry.UserCredentials;
     
    160161    }
    161162
    162     private ProfileDescription createProfile(ComponentRegistry register) throws IOException, JAXBException, DeleteFailedException {
     163    private ProfileDescription createProfile(ComponentRegistry register) throws IOException, JAXBException, DeleteFailedException, ComponentRegistryException {
    163164        ProfileDescription description = ProfileDescription.createNewDescription();
    164165        description.setName("Aap");
     
    295296    }
    296297
    297     private ComponentDescription createComponent(ComponentRegistry registry) throws IOException, DeleteFailedException, JAXBException {
     298    private ComponentDescription createComponent(ComponentRegistry registry) throws IOException, DeleteFailedException, JAXBException, ComponentRegistryException {
    298299        ComponentDescription description = ComponentDescription.
    299300                createNewDescription();
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryImplTest.java

    r1346 r1352  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
     4import clarin.cmdi.componentregistry.ComponentRegistryException;
    45import clarin.cmdi.componentregistry.DeleteFailedException;
    56import clarin.cmdi.componentregistry.UserUnauthorizedException;
     
    3233
    3334    @Test
    34     public void testRegisterProfile() throws JAXBException {
     35    public void testRegisterProfile() throws JAXBException, ComponentRegistryException {
    3536        ComponentRegistry register = getTestRegistry(getRegistryDir());
    3637        ProfileDescription description = ProfileDescription.createNewDescription();
     
    6263
    6364    @Test
    64     public void testRegisterComponent() throws JAXBException {
     65    public void testRegisterComponent() throws JAXBException, ComponentRegistryException {
    6566        ComponentRegistry register = getTestRegistry(getRegistryDir());
    6667        ComponentDescription description = ComponentDescription.
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java

    r1348 r1352  
    1515import javax.ws.rs.core.Response.Status;
    1616
    17 import org.apache.commons.codec.digest.DigestUtils;
    1817import org.junit.Test;
    1918
    2019import clarin.cmdi.componentregistry.ComponentRegistry;
    2120import clarin.cmdi.componentregistry.ComponentRegistryFactory;
    22 import clarin.cmdi.componentregistry.impl.filesystem.ComponentRegistryFactoryImpl;
    2321import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    2422import clarin.cmdi.componentregistry.model.AbstractDescription;
Note: See TracChangeset for help on using the changeset viewer.