Changeset 6700


Ignore:
Timestamp:
10/26/15 14:14:48 (9 years ago)
Author:
Twan Goosen
Message:

Merged fix for #790 to 3.3 branch

Location:
vlo/branches/vlo-3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.3

  • vlo/branches/vlo-3.3/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/MetadataImporter.java

    r6658 r6700  
    4848 * and so on.
    4949 */
    50 @SuppressWarnings({"serial"})
    5150public class MetadataImporter {
    5251
     
    229228     * list of existing data roots will be filtered with the list from user
    230229     *
    231      * @return
     230     * @param dataRoots complete list of DataRoots
     231     * @return list of DataRoots without DataRoots excluded by the user
    232232     */
    233233    protected List<DataRoot> filterDataRootsWithCLArgs(List<DataRoot> dataRoots){
     
    366366                        // are usually not very interesting (think imdi corpus files) and will not be included.
    367367                        updateDocument(solrDocument, cmdiData, file, dataOrigin);
     368                        if(ResourceStructureGraph.getVertex(cmdiData.getId()) != null)
     369                            ResourceStructureGraph.getVertex(cmdiData.getId()).setWasImported(true);
    368370                    } else {
    369371                        nrOfIgnoredFiles++;
     
    549551                }
    550552               
     553                // remove vertices that were not imported
     554                Iterator<String> incomingVertexIter = incomingVertexNames.iterator();
     555                while(incomingVertexIter.hasNext()) {
     556                    String vertexId = incomingVertexIter.next();
     557                    if(ResourceStructureGraph.getVertex(vertexId) == null || !ResourceStructureGraph.getVertex(vertexId).getWasImported())
     558                        incomingVertexIter.remove();
     559                }
     560                Iterator<String> outgoingVertexIter = outgoingVertexNames.iterator();
     561                while(outgoingVertexIter.hasNext()) {
     562                    String vertexId = outgoingVertexIter.next();
     563                    if(ResourceStructureGraph.getVertex(vertexId) == null || !ResourceStructureGraph.getVertex(vertexId).getWasImported())
     564                        outgoingVertexIter.remove();
     565                }
     566               
    551567                if(!incomingVertexNames.isEmpty()) {
    552568                    doc.setField(FacetConstants.FIELD_HAS_PART, incomingVertexNames);
  • vlo/branches/vlo-3.3/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/ResourceStructureGraph.java

    r6213 r6700  
    5353     */
    5454    public static void addResource(String mdSelfLink) {
    55         if (!vertexIdMap.containsKey(mdSelfLink)) {
    56             CmdiVertex newVertex = new CmdiVertex(StringUtils.normalizeIdString(mdSelfLink));
    57             vertexIdMap.put(mdSelfLink, newVertex);
    58         }
    59 
    60         if (!foundVerticesSet.contains(vertexIdMap.get(mdSelfLink))) {
    61             graph.addVertex(vertexIdMap.get(mdSelfLink));
    62             foundVerticesSet.add(vertexIdMap.get(mdSelfLink));
     55        String normalizedMdSelfLink = StringUtils.normalizeIdString(mdSelfLink);
     56        if (!vertexIdMap.containsKey(normalizedMdSelfLink)) {
     57            CmdiVertex newVertex = new CmdiVertex(normalizedMdSelfLink);
     58            vertexIdMap.put(normalizedMdSelfLink, newVertex);
     59        }
     60
     61        if (!foundVerticesSet.contains(vertexIdMap.get(normalizedMdSelfLink))) {
     62            graph.addVertex(vertexIdMap.get(normalizedMdSelfLink));
     63            foundVerticesSet.add(vertexIdMap.get(normalizedMdSelfLink));
    6364        } else {
    6465            LOG.debug("Duplicate resource vertex mdSelfLink: " + mdSelfLink);
     
    7374     */
    7475    public static void addEdge(String sourceVertexId, String targetVertexId) {
     76        String normalizedSourceVertexId = StringUtils.normalizeIdString(sourceVertexId);
     77        String normalizedTargetVertexId = StringUtils.normalizeIdString(targetVertexId);
     78       
    7579        // add vertices
    76         if (!vertexIdMap.containsKey(sourceVertexId)) {
    77             CmdiVertex sourceVertex = new CmdiVertex(StringUtils.normalizeIdString(sourceVertexId));
    78             vertexIdMap.put(sourceVertexId, sourceVertex);
     80        if (!vertexIdMap.containsKey(normalizedSourceVertexId)) {
     81            CmdiVertex sourceVertex = new CmdiVertex(normalizedSourceVertexId);
     82            vertexIdMap.put(normalizedSourceVertexId, sourceVertex);
    7983            graph.addVertex(sourceVertex);
    8084        }
    8185
    82         if (!vertexIdMap.containsKey(targetVertexId)) {
    83             CmdiVertex targetVertex = new CmdiVertex(StringUtils.normalizeIdString(targetVertexId));
    84             vertexIdMap.put(targetVertexId, targetVertex);
     86        if (!vertexIdMap.containsKey(normalizedTargetVertexId)) {
     87            CmdiVertex targetVertex = new CmdiVertex(normalizedTargetVertexId);
     88            vertexIdMap.put(normalizedTargetVertexId, targetVertex);
    8589            graph.addVertex(targetVertex);
    8690        }
     
    8892        // add edge
    8993        try {
    90             graph.addEdge(vertexIdMap.get(sourceVertexId), vertexIdMap.get(targetVertexId));
    91             updateDepthValues(vertexIdMap.get(sourceVertexId), new HashSet<CmdiVertex>());
     94            graph.addEdge(vertexIdMap.get(normalizedSourceVertexId), vertexIdMap.get(normalizedTargetVertexId));
     95            updateDepthValues(vertexIdMap.get(normalizedSourceVertexId), new HashSet<CmdiVertex>());
    9296        } catch (IllegalArgumentException cfe) {
    9397            // was a cycle -> ignore
     
    162166        return foundVerticesSet;
    163167    }
     168   
     169    public static CmdiVertex getVertex(String vertexId) {
     170        return vertexIdMap.get(vertexId);       
     171    }
     172   
     173    public static Map<String, CmdiVertex> getVertexIdMap() {
     174        return vertexIdMap;
     175    }
    164176
    165177    /**
    166178     * Get all vertices that are source of an edge where targetVertex is target.
    167      * In other words get all vertices that are part of targetVertex.
     179     * In other words get all resource vertices that are part of resource targetVertex.
    168180     *
    169181     * @param targetVertex
     
    187199    /**
    188200     * Get all vertices that are target of an edge where sourceVertex is source.
    189      * In other words get all vertices of which sourceVertex is part of.
     201     * In other words get all resource vertices of which resource sourceVertex is part of.
    190202     *
    191203     * @param sourceVertex
     
    273285    private final String id;
    274286    private int hierarchyWeight = 0;
     287    private boolean wasImported = false;
    275288
    276289    public CmdiVertex(String id) {
     
    288301    public int getHierarchyWeight() {
    289302        return hierarchyWeight;
     303    }
     304   
     305    public void setWasImported(boolean wasImported) {
     306        this.wasImported = wasImported;
     307    }
     308   
     309    public boolean getWasImported() {
     310        return wasImported;
    290311    }
    291312
Note: See TracChangeset for help on using the changeset viewer.