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

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

Location:
ComponentRegistry/branches/jeaferversion
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry

    • Property svn:ignore
      •  

        old new  
        77profiles.xml
        88nb-configuration.xml
         9nbactions-Run without tests.xml
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java

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