Project

General

Profile

Revision 5109

Added by daigle almost 11 years ago

Handle the case of trying to insert a conflicting permission order for a document

View differences:

src/edu/ucsb/nceas/metacat/accesscontrol/AccessControlForSingleFile.java
71 71
   */
72 72
  public AccessControlForSingleFile(String accessionNumber) throws AccessControlException
73 73
  {
74
	  
74 75
      //Get rid of dev if myaccessNumber has one;
75 76
	  _docId = DocumentUtil.getDocIdFromString(accessionNumber);
76 77
      if (_docId == null || _docId.equals(""))
......
90 91
	 * @param xmlAccessDAO
91 92
	 *            dao object holding info to insert
92 93
	 */
93
	public void insertPermissions(XMLAccessDAO xmlAccessDAO) throws AccessControlException{
94
	public void insertPermissions(XMLAccessDAO xmlAccessDAO) 
95
			throws AccessControlException, PermOrderException{
94 96
		insertPermissions(xmlAccessDAO.getPrincipalName(), xmlAccessDAO.getPermission(), 
95 97
				xmlAccessDAO.getPermType(), xmlAccessDAO.getPermOrder());
96 98
	}
......
104 106
	 * @param permOrder
105 107
	 * @throws AccessControlException
106 108
	 */
107
	public void insertPermissions(String principalName, Long permission, String permType, String permOrder) throws AccessControlException {
109
	public void insertPermissions(String principalName, Long permission, String permType, String permOrder) 
110
			throws AccessControlException, PermOrderException {
108 111
		try {
109 112
			// The addXMLAccess method will create the permission record if it does not exist.  
110 113
			// It will bitwise OR to permissions if the principal already has a record for this
......
128 131
	public void insertPermissions(String accessBlock) throws AccessControlException {
129 132
		try {			
130 133
			XMLReader parser = null;
131
			DocInfoHandler docInfoHandler = new DocInfoHandler(_docId);
134
			DocInfoHandler docInfoHandler = new DocInfoHandler(_docId); 
132 135
			ContentHandler chandler = docInfoHandler;
133 136

  
134 137
			// Get an instance of the parser
......
143 146
			parser.parse(new InputSource(new StringReader(accessBlock)));
144 147
			
145 148
			XMLAccessAccess xmlAccessAccess = new XMLAccessAccess();
146
			xmlAccessAccess.deleteXMLAccessForDoc(_docId);			
147
			
149
					
148 150
	        Vector<XMLAccessDAO> accessControlList = docInfoHandler.getAccessControlList();
149
	        if (accessControlList != null) {
150
	        	for (XMLAccessDAO xmlAccessDAO : accessControlList) {
151
        			insertPermissions(xmlAccessDAO);
152
					logMetacat.debug("AccessControlForSingleFile.insertPermissions - document " + _docId
153
							+ " permissions added to DB");
154
	            }
155
	        }
151
	        xmlAccessAccess.replaceAccess(_docId, accessControlList);
152

  
156 153
		} catch (PropertyNotFoundException pnfe) {
157 154
			throw new AccessControlException("AccessControlForSingleFile.insertPermissions - "
158 155
					+ "property error when replacing permissions: " + pnfe.getMessage());
......
386 383
			}
387 384
		}
388 385
	}
389

  
390

  
391
	
392
// public String getAccessString() throws AccessControlException {
393
// Vector<XMLAccessDAO> xmlAccessDAOList = null;
394
// try {
395
// XMLAccessAccess xmlAccessAccess = new XMLAccessAccess();
396
//		  xmlAccessDAOList = xmlAccessAccess.getXMLAccessForDoc(docId);
397
//	  } catch (AccessException ae) {
398
//		  throw new AccessControlException("AccessControlForSingleFile.getAccessString - error when getting " + 
399
//				  "access DAO list: " + ae.getMessage());
400
//	  }
401
//	  
402
//	  StringBuffer sb = new StringBuffer();
403
//  
404
//	  for (XMLAccessDAO xmlAccessDAO : xmlAccessDAOList) {
405
//		  sb.append("<access>");
406
//		  
407
//		  sb.append("<permOrder>");
408
//		  sb.append(xmlAccessDAO.getPermOrder());
409
//		  sb.append("</permOrder>");
410
//		  
411
//		  sb.append("<permType>");
412
//		  sb.append(xmlAccessDAO.getPermType());
413
//		  sb.append("</permType>");
414
//		  
415
//		  sb.append("<permission>");
416
//		  sb.append(xmlAccessDAO.getPermission());
417
//		  sb.append("</permission>");
418
//		  
419
//		  sb.append("<principal>");
420
//		  sb.append(xmlAccessDAO.getPrincipalName());
421
//		  sb.append("</principal>");
422
//		  
423
//		  sb.append("</access>");
424
//	  }
425
//  
426
//	  return sb.toString();
427
//	  
428
//  }
429

  
430

  
431 386
}

Also available in: Unified diff