001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.core.operations.services; 013 014import org.nuxeo.ecm.automation.core.Constants; 015import org.nuxeo.ecm.automation.core.annotations.Context; 016import org.nuxeo.ecm.automation.core.annotations.Operation; 017import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 018import org.nuxeo.ecm.automation.core.annotations.Param; 019import org.nuxeo.ecm.automation.core.collectors.DocumentModelCollector; 020import org.nuxeo.ecm.core.api.CoreSession; 021import org.nuxeo.ecm.core.api.DocumentModel; 022import org.nuxeo.ecm.platform.relations.api.DocumentRelationManager; 023 024/** 025 * @author Nuxeo 026 */ 027@Operation(id = DeleteRelation.ID, category = Constants.CAT_SERVICES, label = "Delete Relation", description = "Delete a relation between 2 documents. The subject of the relation will be the input of the operation and the object of the relation will be retrieved from the context using the 'object' field. The 'predicate' field specifies the relation predicate (When using a known predicate, use the full URL like 'purl.org/dc/terms/IsBasedOn', unknown predicates will be treated as plain strings and be the same on the subject and object). The 'outgoing' flag indicates the direction of the relation - the default is false which means the relation will go from the input object to the object specified as 'object' parameter. Return back the subject document.", aliases = { "Relations.DeleteRelation" }) 028public class DeleteRelation { 029 030 public static final String ID = "Document.DeleteRelation"; 031 032 @Context 033 protected CoreSession session; 034 035 @Context 036 protected DocumentRelationManager relations; 037 038 @Param(name = "object") 039 protected DocumentModel object; 040 041 @Param(name = "predicate") 042 protected String predicate; 043 044 @Param(name = "outgoing", required = false, values = "false") 045 protected boolean outgoing = false; 046 047 @OperationMethod(collector = DocumentModelCollector.class) 048 public DocumentModel run(DocumentModel doc) { 049 relations.deleteRelation(session, doc, object, predicate, outgoing); 050 return doc; 051 } 052}