Project

General

Profile

« Previous | Next » 

Revision 8986

Added by Jing Tao about 10 years ago

Fixed a bug that the solr index of data files doesn't reflect the change of access control.

View differences:

src/edu/ucsb/nceas/metacat/MetacatHandler.java
1838 1838
                  
1839 1839
                  // handle inserts
1840 1840
                  try {
1841
                	// create the system metadata  
1842
                    sysMeta = SystemMetadataFactory.createSystemMetadata(newdocid, true, false);
1841
                   // create the system metadata. During the creatation, the data file in the eml may need to be reindexed.
1842
                   boolean reindexDataObject = true;
1843
                   sysMeta = SystemMetadataFactory.createSystemMetadata(reindexDataObject, newdocid, true, false);
1843 1844
                    
1844 1845
                    // save it to the map
1845 1846
                    HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
src/edu/ucsb/nceas/metacat/dataone/SystemMetadataFactory.java
86 86
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException;
87 87
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
88 88
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
89
import edu.ucsb.nceas.metacat.index.MetacatSolrIndex;
89 90
import edu.ucsb.nceas.metacat.properties.PropertyService;
90 91
import edu.ucsb.nceas.metacat.replication.ReplicationService;
91 92
import edu.ucsb.nceas.metacat.shared.AccessException;
......
103 104
	 */
104 105
	private static boolean updateExisting = true;
105 106
	
107
	
108
	
106 109
	/**
110
	 * Create a system metadata object for insertion into metacat
111
	 * @param localId
112
	 * @param includeORE
113
	 * @param downloadData
114
	 * @return
115
	 * @throws McdbException
116
	 * @throws McdbDocNotFoundException
117
	 * @throws SQLException
118
	 * @throws IOException
119
	 * @throws AccessionNumberException
120
	 * @throws ClassNotFoundException
121
	 * @throws InsufficientKarmaException
122
	 * @throws ParseLSIDException
123
	 * @throws PropertyNotFoundException
124
	 * @throws BaseException
125
	 * @throws NoSuchAlgorithmException
126
	 * @throws JiBXException
127
	 * @throws AccessControlException
128
	 * @throws HandlerException
129
	 * @throws SAXException
130
	 * @throws AccessException
131
	 */
132
	public static SystemMetadata createSystemMetadata(String localId, boolean includeORE, boolean downloadData)
133
            throws McdbException, McdbDocNotFoundException, SQLException,
134
            IOException, AccessionNumberException, ClassNotFoundException,
135
            InsufficientKarmaException, ParseLSIDException,
136
            PropertyNotFoundException, BaseException, NoSuchAlgorithmException,
137
            JiBXException, AccessControlException, HandlerException, SAXException, AccessException {
138
	        boolean indexDataFile = false;
139
	        return createSystemMetadata(indexDataFile, localId, includeORE, downloadData);
140
	}
141
	/**
107 142
	 * Creates a system metadata object for insertion into metacat
143
	 * @param indexDataFile
144
	 *            Indicate if we need to index data file.
108 145
	 * 
109 146
	 * @param localId
110 147
	 *            The local document identifier
......
119 156
	 * @throws AccessControlException 
120 157
	 * @throws AccessException 
121 158
	 */
122
	public static SystemMetadata createSystemMetadata(String localId, boolean includeORE, boolean downloadData)
159
	public static SystemMetadata createSystemMetadata(boolean indexDataFile, String localId, boolean includeORE, boolean downloadData)
123 160
			throws McdbException, McdbDocNotFoundException, SQLException,
124 161
			IOException, AccessionNumberException, ClassNotFoundException,
125 162
			InsufficientKarmaException, ParseLSIDException,
......
507 544
							// update the values
508 545
							HazelcastService.getInstance().getSystemMetadataMap().put(dataSysMeta.getIdentifier(), dataSysMeta);
509 546
							
547
							// reindex data file if need it.
548
							logMetacat.debug("do we need to reindex guid "+dataGuid.getValue()+"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~?"+indexDataFile);
549
							if(indexDataFile) {
550
							    reindexDataFile(dataSysMeta.getIdentifier(), dataSysMeta);
551
							}
552

  
510 553
							// include as part of the ORE package
511 554
							dataIds.add(dataGuid);
512 555
	
......
606 649

  
607 650
		return sysMeta;
608 651
	}
652
	
653
	/*
654
	 * Re-index the data file since the access rule was changed during the inserting of the eml document.
655
	 * (During first time to index the data file in Metacat API, the eml hasn't been inserted)
656
	 */
657
	private static void reindexDataFile(Identifier id, SystemMetadata sysmeta) {
658
	    try {
659
	        logMetacat.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ reindex"+id.getValue());
660
	        //set the archive to true to remove index.
661
	        sysmeta.setArchived(true);
662
            MetacatSolrIndex.getInstance().submit(id, sysmeta, null, true);
663
            //re-insert the index
664
            sysmeta.setArchived(false);
665
            MetacatSolrIndex.getInstance().submit(id, sysmeta, null, true);
666
        } catch (Exception e) {
667
            // TODO Auto-generated catch block
668
            logMetacat.warn("Can't reindex the data object "+id.getValue()+" since "+e.getMessage());
669
            //e.printStackTrace();
670
        }
671
	}
609 672

  
610 673
	/**
611 674
	 * Checks for potential ORE object existence 

Also available in: Unified diff