001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Florent Guillaume 016 */ 017package org.nuxeo.apidoc.introspection; 018 019import java.util.Arrays; 020import java.util.List; 021 022import org.nuxeo.apidoc.api.BaseNuxeoArtifact; 023import org.nuxeo.apidoc.api.OperationInfo; 024import org.nuxeo.ecm.automation.OperationDocumentation; 025import org.nuxeo.ecm.automation.OperationDocumentation.Param; 026 027/** 028 * DTO for an {@link OperationInfo}, used for the runtime implementation. 029 */ 030public class OperationInfoImpl extends BaseNuxeoArtifact implements OperationInfo { 031 032 public final OperationDocumentation op; 033 034 public final String version; 035 036 protected final String operationClass; 037 038 protected final String contributingComponent; 039 040 public OperationInfoImpl(OperationDocumentation op, String version, String operationClass, 041 String contributingComponent) { 042 this.op = op; 043 this.version = version; 044 this.operationClass = operationClass; 045 if (contributingComponent == null || contributingComponent.isEmpty()) { 046 this.contributingComponent = OperationInfo.BUILT_IN; 047 } else { 048 String[] parts = contributingComponent.split(":"); 049 if (parts.length > 1) { 050 this.contributingComponent = parts[1]; 051 } else { 052 this.contributingComponent = contributingComponent; 053 } 054 } 055 } 056 057 @Override 058 public String getName() { 059 return op.getId(); 060 } 061 062 @Override 063 public String getId() { 064 return ARTIFACT_PREFIX + op.getId(); 065 } 066 067 @Override 068 public String[] getAliases() { 069 return op.getAliases(); 070 } 071 072 @Override 073 public String getDescription() { 074 return op.getDescription(); 075 } 076 077 @Override 078 public String[] getSignature() { 079 return op.getSignature(); 080 } 081 082 @Override 083 public String getCategory() { 084 return op.getCategory(); 085 } 086 087 @Override 088 public String getUrl() { 089 return op.getUrl(); 090 } 091 092 @Override 093 public String getLabel() { 094 return op.getLabel(); 095 } 096 097 @Override 098 public String getRequires() { 099 return op.getRequires(); 100 } 101 102 @Override 103 public String getSince() { 104 return op.since; 105 } 106 107 @Override 108 public List<Param> getParams() { 109 return Arrays.asList(op.getParams()); 110 } 111 112 @Override 113 public String getVersion() { 114 return version; 115 } 116 117 @Override 118 public String getArtifactType() { 119 return TYPE_NAME; 120 } 121 122 @Override 123 public String getHierarchyPath() { 124 return "/"; 125 } 126 127 @Override 128 public int compareTo(OperationInfo o) { 129 String s1 = getLabel() == null ? getId() : getLabel(); 130 String s2 = o.getLabel() == null ? o.getId() : o.getLabel(); 131 return s1.compareTo(s2); 132 } 133 134 public String getOperationClass() { 135 return operationClass; 136 } 137 138 public String getContributingComponent() { 139 return contributingComponent; 140 } 141 142}