Project

General

Profile

« Previous | Next » 

Revision 6882

remove method: assertRelation
https://redmine.dataone.org/issues/2158

View differences:

test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java
38 38
import org.apache.commons.io.IOUtils;
39 39
import org.dataone.client.D1Client;
40 40
import org.dataone.service.exceptions.BaseException;
41
import org.dataone.service.exceptions.InsufficientResources;
42 41
import org.dataone.service.exceptions.NotAuthorized;
43 42
import org.dataone.service.exceptions.NotFound;
44 43
import org.dataone.service.exceptions.NotImplemented;
......
88 87
		TestSuite suite = new TestSuite();
89 88
		suite.addTest(new CNodeServiceTest("initialize"));
90 89
		
91
		suite.addTest(new CNodeServiceTest("testAssertRelation"));
92 90
		suite.addTest(new CNodeServiceTest("testChecksum"));
93 91
		suite.addTest(new CNodeServiceTest("testCreate"));
94 92
		suite.addTest(new CNodeServiceTest("testGet"));
......
218 216
        }
219 217
	}
220 218
	
221
	public void testAssertRelation() {
222
	    printTestHeader("testAssertRelation");
223

  
224
	    try {
225
            Session session = getTestSession();
226
			Identifier guid = new Identifier();
227
			guid.setValue("testAssertRelation." + System.currentTimeMillis());
228
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
229
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
230
			Identifier describePid = new Identifier();
231
			describePid.setValue("describePid." + System.currentTimeMillis());
232
			sysmeta.setObsoletes(describePid);
233
			// save it
234
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
235
			assertEquals(guid.getValue(), retGuid.getValue());
236
			// save the other
237
			InputStream object2 = new ByteArrayInputStream("test".getBytes("UTF-8"));
238
			SystemMetadata describeSysmeta = createSystemMetadata(describePid, session.getSubject(), object2);
239
			Identifier retDescribePid = CNodeService.getInstance(request).registerSystemMetadata(session, describePid, describeSysmeta);
240
			assertEquals(describePid.getValue(), retDescribePid.getValue());
241
			// check it
242
			boolean result = CNodeService.getInstance(request).assertRelation(session, guid, "obsoletes", describePid);
243
			assertTrue(result);
244
        } catch(Exception e) {
245
        	e.printStackTrace();
246
            fail("Unexpected error: " + e.getMessage());
247
        }
248
	}
249
	
250 219
	public void testChecksum() {
251 220
	    printTestHeader("testChecksum");
252 221

  
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
119 119
    protected static final String RESOURCE_RESERVE = "reserve";
120 120
    protected static final String RESOURCE_FORMATS = "formats";
121 121
    protected static final String RESOURCE_RESOLVE = "resolve";
122
    protected static final String RESOURCE_ASSERT_RELATION = "assertRelation";
123 122
    protected static final String RESOURCE_OWNER = "owner";
124 123
    protected static final String RESOURCE_REPLICATION_POLICY = "replicaPolicies";
125 124
    protected static final String RESOURCE_REPLICATION_META = "replicaMetadata";
......
191 190
                        reserve();
192 191
                        status = true;
193 192
                    }
194
                } else if (resource.startsWith(RESOURCE_ASSERT_RELATION)) {
195

  
196
                    // after the command
197
                    extra = parseTrailing(resource, RESOURCE_ASSERT_RELATION);
198

  
199
                    // reserve the ID (in params)
200
                    if (httpVerb == GET) {
201
                        assertRelation(extra);
202
                        status = true;
203
                    }
204 193
                } else if (resource.startsWith(RESOURCE_RESOLVE)) {
205 194

  
206 195
                    // after the command
......
835 824
    }
836 825

  
837 826
    /**
838
     * Assert that a relationship exists between two resources
839
     * 
840
     * @param id
841
     * @return
842
     * @throws InvalidToken
843
     * @throws ServiceFailure
844
     * @throws NotAuthorized
845
     * @throws NotFound
846
     * @throws InvalidRequest
847
     * @throws NotImplemented
848
     */
849
    private boolean assertRelation(String id) throws InvalidToken,
850
            ServiceFailure, NotAuthorized, NotFound, InvalidRequest,
851
            NotImplemented {
852
        Identifier pidOfSubject = new Identifier();
853
        pidOfSubject.setValue(id);
854
        String relationship = null;
855
        try {
856
            relationship = params.get("relationship")[0];
857
        } catch (Exception e) {
858
            logMetacat.warn("relationship not specified");
859
        }
860
        Identifier pidOfObject = new Identifier();
861
        try {
862
            String objPid = params.get("pidOfObject")[0];
863
            pidOfObject.setValue(objPid);
864
        } catch (Exception e) {
865
            logMetacat.warn("pidOfObject not specified");
866
        }
867
        boolean result = CNodeService.getInstance(request).assertRelation(
868
                session, pidOfSubject, relationship, pidOfObject);
869
        response.setStatus(200);
870
        response.setContentType("text/xml");
871
        return result;
872
    }
873

  
874
    /**
875 827
     * Set the owner of a resource
876 828
     * 
877 829
     * @param id

Also available in: Unified diff