Project

General

Profile

« Previous | Next » 

Revision 8591

make all package contents publicly readable when publishing with a DOI. https://projects.ecoinformatics.org/ecoinfo/issues/6415

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
81 81
import org.dataone.service.mn.tier3.v1.MNStorage;
82 82
import org.dataone.service.mn.tier4.v1.MNReplication;
83 83
import org.dataone.service.mn.v1.MNQuery;
84
import org.dataone.service.types.v1.AccessRule;
84 85
import org.dataone.service.types.v1.Checksum;
85 86
import org.dataone.service.types.v1.DescribeResponse;
86 87
import org.dataone.service.types.v1.Event;
......
1313 1314
            
1314 1315
        }
1315 1316
    }
1317
    
1318
    private SystemMetadata makePublicIfNot(SystemMetadata sysmeta, Identifier pid) throws ServiceFailure, InvalidToken, NotFound, NotImplemented, InvalidRequest {
1319
    	// check if it is publicly readable
1320
		boolean isPublic = false;
1321
		Subject publicSubject = new Subject();
1322
		publicSubject.setValue(Constants.SUBJECT_PUBLIC);
1323
		Session publicSession = new Session();
1324
		publicSession.setSubject(publicSubject);
1325
		AccessRule publicRule = new AccessRule();
1326
		publicRule.addPermission(Permission.READ);
1327
		publicRule.addSubject(publicSubject);
1328
		
1329
		// see if we need to add the rule
1330
		try {
1331
			isPublic = this.isAuthorized(publicSession, pid, Permission.READ);
1332
		} catch (NotAuthorized na) {
1333
			// well, certainly not authorized for public read!
1334
		}
1335
		if (!isPublic) {
1336
			sysmeta.getAccessPolicy().addAllow(publicRule);
1337
		}
1338
		
1339
		return sysmeta;
1340
    }
1316 1341

  
1317 1342
	@Override
1318 1343
	public Identifier generateIdentifier(Session session, String scheme, String fragment)
......
1647 1672
		sysmeta.setObsoletes(originalIdentifier);
1648 1673
		sysmeta.setObsoletedBy(null);
1649 1674
		
1675
		// ensure it is publicly readable
1676
		sysmeta = makePublicIfNot(sysmeta, originalIdentifier);
1677
		
1650 1678
		// get the bytes
1651 1679
		InputStream inputStream = this.get(session, originalIdentifier);
1652 1680
		
......
1685 1713
				Map<Identifier, Map<Identifier, List<Identifier>>> resourceMapStructure = ResourceMapFactory.getInstance().parseResourceMap(oreInputStream);
1686 1714
				Map<Identifier, List<Identifier>> sciMetaMap = resourceMapStructure.get(potentialOreIdentifier);
1687 1715
				List<Identifier> dataIdentifiers = sciMetaMap.get(originalIdentifier);
1688
				
1689
				// TODO: ensure all data package objects allow public read
1690
	
1716
					
1691 1717
				// reconstruct the ORE with the new identifiers
1692 1718
				sciMetaMap.remove(originalIdentifier);
1693 1719
				sciMetaMap.put(newIdentifier, dataIdentifiers);
......
1713 1739
				oreSysMeta.setSize(BigInteger.valueOf(resourceMapString.getBytes("UTF-8").length));
1714 1740
				oreSysMeta.setChecksum(ChecksumUtil.checksum(resourceMapString.getBytes("UTF-8"), oreSysMeta.getChecksum().getAlgorithm()));
1715 1741
				
1742
				// ensure ORE is publicly readable
1743
				oreSysMeta = makePublicIfNot(sysmeta, potentialOreIdentifier);
1744
				
1745
				// ensure all data objects allow public read
1746
				List<String> pidsToSync = new ArrayList<String>();
1747
				for (Identifier dataId: dataIdentifiers) {
1748
					SystemMetadata dataSysMeta = this.getSystemMetadata(session, dataId);
1749
					dataSysMeta = makePublicIfNot(dataSysMeta, dataId);
1750
					this.updateSystemMetadata(dataSysMeta);
1751
					pidsToSync.add(dataId.getValue());
1752
				}
1753
				SyncAccessPolicy sap = new SyncAccessPolicy();
1754
				try {
1755
					sap.sync(pidsToSync);
1756
				} catch (Exception e) {
1757
					// ignore
1758
					logMetacat.warn("Error attempting to sync access for data objects when publishing package");
1759
				}
1760
				
1716 1761
				// save the updated ORE
1717 1762
				this.update(
1718 1763
						session, 
......
1730 1775
	
1731 1776
					@SuppressWarnings("unused")
1732 1777
					SystemMetadata extraSysMeta = SystemMetadataFactory.createSystemMetadata(newLocalId, true, false);
1733
					// should be done generating the ORE here
1778
					// should be done generating the ORE here, and the same permissions were used from the metadata object
1734 1779
					
1735 1780
				} catch (Exception e) {
1736 1781
					// oops, guess there was a problem - no package for you

Also available in: Unified diff