001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.oozie.command.wf; 019 020 import org.apache.oozie.ErrorCode; 021 import org.apache.oozie.XException; 022 import org.apache.oozie.service.JPAService; 023 import org.apache.oozie.service.Services; 024 import org.apache.oozie.util.ParamChecker; 025 import org.apache.oozie.command.CommandException; 026 import org.apache.oozie.command.PreconditionException; 027 import org.apache.oozie.executor.jpa.WorkflowIdGetForExternalIdJPAExecutor; 028 029 public class ExternalIdXCommand extends WorkflowXCommand<String> { 030 private String externalId; 031 032 public ExternalIdXCommand(String externalId) { 033 super("externalId", "externalId", 1); 034 this.externalId = ParamChecker.notEmpty(externalId, "externalId"); 035 } 036 037 @Override 038 protected boolean isLockRequired() { 039 return false; 040 } 041 042 @Override 043 protected String getEntityKey() { 044 return this.externalId; 045 } 046 047 @Override 048 protected void loadState() throws CommandException { 049 } 050 051 @Override 052 protected void verifyPrecondition() throws CommandException, PreconditionException { 053 } 054 055 @Override 056 protected String execute() throws CommandException { 057 try { 058 JPAService jpaService = Services.get().get(JPAService.class); 059 String wfId = null; 060 if (jpaService != null) { 061 wfId = jpaService.execute(new WorkflowIdGetForExternalIdJPAExecutor(externalId)); 062 } 063 else { 064 LOG.error(ErrorCode.E0610); 065 } 066 return wfId; 067 } 068 catch (XException ex) { 069 throw new CommandException(ex); 070 } 071 } 072 073 }