blob: efbf0ffa1c714a590fa5e157e72c50cba68747d4 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>UDDICustodyTransferImpl.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">jUDDI Core - OpenJPA</a> &gt; <a href="index.source.html" class="el_package">org.apache.juddi.api.impl</a> &gt; <span class="el_source">UDDICustodyTransferImpl.java</span></div><h1>UDDICustodyTransferImpl.java</h1><pre class="source lang-java linenums">/*
* Copyright 2001-2008 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.juddi.api.impl;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jws.WebService;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Holder;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.juddi.api.util.CustodyTransferQuery;
import org.apache.juddi.api.util.QueryStatus;
import org.apache.juddi.config.AppConfig;
import org.apache.juddi.config.PersistenceManager;
import org.apache.juddi.config.Property;
import org.apache.juddi.mapping.MappingApiToModel;
import org.apache.juddi.mapping.MappingModelToApi;
import org.apache.juddi.model.BindingTemplate;
import org.apache.juddi.model.BusinessEntity;
import org.apache.juddi.model.BusinessService;
import org.apache.juddi.model.Operator;
import org.apache.juddi.model.Tmodel;
import org.apache.juddi.model.TransferTokenKey;
import org.apache.juddi.model.UddiEntity;
import org.apache.juddi.model.UddiEntityPublisher;
import org.apache.juddi.query.util.DynamicQuery;
import org.apache.juddi.replication.ReplicationNotifier;
import org.apache.juddi.v3.client.UDDIService;
import org.apache.juddi.v3.error.ErrorMessage;
import org.apache.juddi.v3.error.FatalErrorException;
import org.apache.juddi.v3.error.InvalidValueException;
import org.apache.juddi.v3.error.TransferNotAllowedException;
import org.apache.juddi.validation.ValidateCustodyTransfer;
import org.uddi.api_v3.OperationalInfo;
import org.uddi.custody_v3.DiscardTransferToken;
import org.uddi.custody_v3.KeyBag;
import org.uddi.custody_v3.TransferEntities;
import org.uddi.custody_v3.TransferOperationalInfo;
import org.uddi.repl_v3.ChangeRecord;
import org.uddi.repl_v3.ChangeRecordIDType;
import org.uddi.repl_v3.ChangeRecordNewData;
import org.uddi.repl_v3.TransferCustody;
import org.uddi.v3_service.DispositionReportFaultMessage;
import org.uddi.v3_service.UDDICustodyTransferPortType;
import org.uddi.v3_service.UDDIReplicationPortType;
/**
* This implements the UDDI v3 Custody Transfer API web service
*
*/
@WebService(serviceName = &quot;UDDICustodyTransferService&quot;,
endpointInterface = &quot;org.uddi.v3_service.UDDICustodyTransferPortType&quot;,
targetNamespace = &quot;urn:uddi-org:v3_service&quot;)
public class UDDICustodyTransferImpl extends AuthenticatedService implements UDDICustodyTransferPortType {
public static final String TRANSFER_TOKEN_PREFIX = &quot;transfertoken:&quot;;
public static final int DEFAULT_TRANSFEREXPIRATION_DAYS = 3;
<span class="fc" id="L90"> private static Log logger = LogFactory.getLog(UDDICustodyTransferImpl.class);</span>
<span class="fc" id="L92"> private static DatatypeFactory df = null;</span>
private UDDIServiceCounter serviceCounter;
public UDDICustodyTransferImpl() {
<span class="fc" id="L96"> super();</span>
<span class="fc" id="L97"> serviceCounter = ServiceCounterLifecycleResource.getServiceCounter(this.getClass());</span>
<span class="fc" id="L98"> init();</span>
<span class="fc" id="L99"> }</span>
private static synchronized void init() {
<span class="pc bpc" id="L102" title="1 of 2 branches missed."> if (df == null) {</span>
try {
<span class="fc" id="L104"> df = DatatypeFactory.newInstance();</span>
<span class="nc" id="L105"> } catch (DatatypeConfigurationException ex) {</span>
<span class="nc" id="L106"> Logger.getLogger(UDDICustodyTransferImpl.class.getName()).log(Level.SEVERE, null, ex);</span>
<span class="fc" id="L107"> }</span>
}
<span class="fc" id="L109"> }</span>
@SuppressWarnings(&quot;unchecked&quot;)
@Override
public void discardTransferToken(DiscardTransferToken body)
throws DispositionReportFaultMessage {
<span class="nc" id="L115"> long startTime = System.currentTimeMillis();</span>
<span class="nc" id="L117"> EntityManager em = PersistenceManager.getEntityManager();</span>
<span class="nc" id="L118"> EntityTransaction tx = em.getTransaction();</span>
try {
<span class="nc" id="L120"> tx.begin();</span>
<span class="nc" id="L122"> UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());</span>
<span class="nc" id="L124"> new ValidateCustodyTransfer(publisher).validateDiscardTransferToken(em, body);</span>
<span class="nc" id="L126"> org.uddi.custody_v3.TransferToken apiTransferToken = body.getTransferToken();</span>
<span class="nc bnc" id="L127" title="All 2 branches missed."> if (apiTransferToken != null) {</span>
String transferTokenId;
try {
<span class="nc" id="L130"> transferTokenId = new String(apiTransferToken.getOpaqueToken(), UTF8);</span>
<span class="nc" id="L131"> } catch (UnsupportedEncodingException ex) {</span>
<span class="nc" id="L132"> throw new InvalidValueException(new ErrorMessage(&quot;errors.stringEncoding&quot;));</span>
<span class="nc" id="L133"> }</span>
<span class="nc" id="L134"> org.apache.juddi.model.TransferToken modelTransferToken = em.find(org.apache.juddi.model.TransferToken.class, transferTokenId);</span>
<span class="nc bnc" id="L135" title="All 2 branches missed."> if (modelTransferToken != null) {</span>
<span class="nc" id="L136"> em.remove(modelTransferToken);</span>
}
}
<span class="nc" id="L140"> KeyBag keyBag = body.getKeyBag();</span>
<span class="nc bnc" id="L141" title="All 2 branches missed."> if (keyBag != null) {</span>
<span class="nc" id="L142"> List&lt;String&gt; keyList = keyBag.getKey();</span>
<span class="nc" id="L143"> Vector&lt;DynamicQuery.Parameter&gt; params = new Vector&lt;DynamicQuery.Parameter&gt;(0);</span>
<span class="nc bnc" id="L144" title="All 2 branches missed."> for (String key : keyList) {</span>
// Creating parameters for key-checking query
<span class="nc" id="L146"> DynamicQuery.Parameter param = new DynamicQuery.Parameter(&quot;UPPER(ttk.entityKey)&quot;,</span>
<span class="nc" id="L147"> key.toUpperCase(),</span>
DynamicQuery.PREDICATE_EQUALS);
<span class="nc" id="L150"> params.add(param);</span>
<span class="nc" id="L151"> }</span>
// Find the associated transfer tokens and remove them.
<span class="nc" id="L154"> DynamicQuery getTokensQry = new DynamicQuery();</span>
<span class="nc" id="L155"> getTokensQry.append(&quot;select distinct ttk.transferToken from TransferTokenKey ttk&quot;).pad();</span>
<span class="nc" id="L156"> getTokensQry.WHERE().pad().appendGroupedOr(params.toArray(new DynamicQuery.Parameter[0]));</span>
<span class="nc" id="L158"> Query qry = getTokensQry.buildJPAQuery(em);</span>
<span class="nc" id="L159"> List&lt;org.apache.juddi.model.TransferToken&gt; tokensToDelete = qry.getResultList();</span>
<span class="nc bnc" id="L160" title="All 4 branches missed."> if (tokensToDelete != null &amp;&amp; tokensToDelete.size() &gt; 0) {</span>
<span class="nc bnc" id="L161" title="All 2 branches missed."> for (org.apache.juddi.model.TransferToken tt : tokensToDelete) {</span>
<span class="nc" id="L162"> em.remove(tt);</span>
<span class="nc" id="L163"> }</span>
}
}
<span class="nc" id="L167"> tx.commit();</span>
<span class="nc" id="L168"> long procTime = System.currentTimeMillis() - startTime;</span>
<span class="nc" id="L169"> serviceCounter.update(CustodyTransferQuery.DISCARD_TRANSFERTOKEN,</span>
QueryStatus.SUCCESS, procTime);
} finally {
<span class="nc bnc" id="L173" title="All 4 branches missed."> if (tx.isActive()) {</span>
<span class="nc" id="L174"> tx.rollback();</span>
}
<span class="nc" id="L176"> em.close();</span>
<span class="nc" id="L177"> }</span>
<span class="nc" id="L178"> }</span>
@Override
public void getTransferToken(String authInfo, KeyBag keyBag,
Holder&lt;String&gt; nodeID, Holder&lt;XMLGregorianCalendar&gt; expirationTime,
Holder&lt;byte[]&gt; opaqueToken) throws DispositionReportFaultMessage {
<span class="fc" id="L184"> long startTime = System.currentTimeMillis();</span>
<span class="fc" id="L186"> EntityManager em = PersistenceManager.getEntityManager();</span>
<span class="fc" id="L187"> EntityTransaction tx = em.getTransaction();</span>
try {
<span class="fc" id="L189"> tx.begin();</span>
<span class="fc" id="L191"> UddiEntityPublisher publisher = this.getEntityPublisher(em, authInfo);</span>
<span class="fc" id="L193"> new ValidateCustodyTransfer(publisher).validateGetTransferToken(em, keyBag);</span>
<span class="fc" id="L195"> int transferExpirationDays = DEFAULT_TRANSFEREXPIRATION_DAYS;</span>
try {
<span class="fc" id="L197"> transferExpirationDays = AppConfig.getConfiguration().getInt(Property.JUDDI_TRANSFER_EXPIRATION_DAYS);</span>
// For output
<span class="fc" id="L199"> nodeID.value = AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID);</span>
<span class="nc" id="L200"> } catch (ConfigurationException ce) {</span>
<span class="nc" id="L201"> throw new FatalErrorException(new ErrorMessage(&quot;errors.configuration.Retrieval&quot;));</span>
<span class="fc" id="L202"> }</span>
<span class="fc" id="L204"> String transferKey = TRANSFER_TOKEN_PREFIX + UUID.randomUUID();</span>
<span class="fc" id="L205"> org.apache.juddi.model.TransferToken transferToken = new org.apache.juddi.model.TransferToken();</span>
<span class="fc" id="L206"> transferToken.setTransferToken(transferKey);</span>
try {
// For output
<span class="fc" id="L209"> opaqueToken.value = transferKey.getBytes(UTF8);</span>
<span class="nc" id="L210"> } catch (UnsupportedEncodingException ex) {</span>
<span class="nc" id="L211"> throw new InvalidValueException(new ErrorMessage(&quot;errors.stringEncoding&quot;));</span>
<span class="fc" id="L212"> }</span>
<span class="fc" id="L214"> GregorianCalendar gc = new GregorianCalendar();</span>
<span class="fc" id="L215"> gc.add(GregorianCalendar.DAY_OF_MONTH, transferExpirationDays);</span>
<span class="fc" id="L217"> transferToken.setExpirationDate(gc.getTime());</span>
try {
<span class="fc" id="L220"> DatatypeFactory df = DatatypeFactory.newInstance();</span>
// For output
<span class="fc" id="L222"> expirationTime.value = df.newXMLGregorianCalendar(gc);</span>
<span class="nc" id="L223"> } catch (DatatypeConfigurationException ce) {</span>
<span class="nc" id="L224"> throw new FatalErrorException(new ErrorMessage(&quot;errors.Unspecified&quot;));</span>
<span class="fc" id="L225"> }</span>
<span class="fc" id="L227"> List&lt;String&gt; keyList = keyBag.getKey();</span>
<span class="fc bfc" id="L228" title="All 2 branches covered."> for (String key : keyList) {</span>
<span class="fc" id="L229"> TransferTokenKey tokenKey = new TransferTokenKey(transferToken, key);</span>
<span class="fc" id="L230"> transferToken.getTransferKeys().add(tokenKey);</span>
<span class="fc" id="L231"> }</span>
<span class="fc" id="L233"> em.persist(transferToken);</span>
<span class="fc" id="L235"> tx.commit();</span>
<span class="fc" id="L237"> long procTime = System.currentTimeMillis() - startTime;</span>
<span class="fc" id="L238"> serviceCounter.update(CustodyTransferQuery.GET_TRANSFERTOKEN,</span>
QueryStatus.SUCCESS, procTime);
} finally {
<span class="pc bpc" id="L242" title="3 of 4 branches missed."> if (tx.isActive()) {</span>
<span class="nc" id="L243"> tx.rollback();</span>
}
<span class="pc" id="L245"> em.close();</span>
<span class="fc" id="L246"> }</span>
<span class="fc" id="L247"> }</span>
@Override
public void transferEntities(TransferEntities body)
throws DispositionReportFaultMessage {
<span class="fc" id="L252"> long startTime = System.currentTimeMillis();</span>
<span class="fc" id="L254"> EntityManager em = PersistenceManager.getEntityManager();</span>
<span class="fc" id="L255"> EntityTransaction tx = em.getTransaction();</span>
<span class="fc" id="L256"> List&lt;ChangeRecord&gt; changes = new ArrayList&lt;ChangeRecord&gt;();</span>
try {
<span class="fc" id="L258"> tx.begin();</span>
<span class="fc" id="L260"> UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());</span>
<span class="fc" id="L262"> ValidateCustodyTransfer verifier = new ValidateCustodyTransfer(publisher);</span>
//if the destination transfer is to a different node,
<span class="pc bpc" id="L265" title="1 of 2 branches missed."> if (!verifier.validateTransferEntities(em, body)) {</span>
//i don't own these entities, so tell the owner to transfer to me.
//look up the replication config endpoint for that node and trigger the transfer, then return
//ok this is a node to node transfer, first up a replication client to the destination node
<span class="nc" id="L270"> String sourceNode = null;</span>
try {
<span class="nc" id="L272"> KeyBag keyBag = body.getKeyBag();</span>
<span class="nc" id="L273"> List&lt;String&gt; keyList = keyBag.getKey();</span>
<span class="nc bnc" id="L274" title="All 2 branches missed."> for (String key : keyList) {</span>
<span class="nc" id="L275"> UddiEntity uddiEntity = em.find(UddiEntity.class, key);</span>
<span class="nc bnc" id="L277" title="All 2 branches missed."> if (uddiEntity!=null) {</span>
<span class="nc" id="L278"> uddiEntity.setIsTransferInProgress(true);</span>
<span class="nc" id="L279"> sourceNode = uddiEntity.getNodeId();</span>
<span class="nc" id="L280"> em.merge(uddiEntity);</span>
//save the fact we are expecting a transfer
}
else
{
<span class="nc" id="L285"> logger.warn(&quot;couldn't find a record for key &quot; + key);</span>
}
<span class="nc" id="L287"> }</span>
<span class="nc bnc" id="L288" title="All 2 branches missed."> if (sourceNode==null){</span>
<span class="nc" id="L289"> logger.warn(&quot;unable to process transfer, could not locate the source node, perhaps it hasn't been replicated to this node yet?&quot;)</span>
;
<span class="nc" id="L291"> throw new Exception(&quot;unable to process transfer, could not locate the source node for any of the specific keys, perhaps it hasn't been replicated to this node yet?&quot;);</span>
}
<span class="nc" id="L294"> UDDIReplicationPortType replicationClient = getReplicationClient(sourceNode);</span>
<span class="nc bnc" id="L295" title="All 2 branches missed."> if (replicationClient == null) {</span>
<span class="nc" id="L296"> throw new Exception(&quot;Unknown node. is it in the replication graph?&quot; + sourceNode);</span>
}
<span class="nc" id="L298"> TransferCustody transferCustody = new TransferCustody();</span>
<span class="nc" id="L299"> transferCustody.setTransferToken(body.getTransferToken());</span>
<span class="nc" id="L300"> transferCustody.setKeyBag(body.getKeyBag());</span>
<span class="nc" id="L301"> transferCustody.setTransferOperationalInfo(new TransferOperationalInfo());</span>
<span class="nc" id="L302"> transferCustody.getTransferOperationalInfo().setAuthorizedName(publisher.getAuthorizedName());</span>
<span class="nc" id="L303"> transferCustody.getTransferOperationalInfo().setNodeID(getNode());</span>
//and trigger the transfer
<span class="nc" id="L306"> logger.info(&quot;AUDIT, transfering &quot; + transferCustody.getKeyBag().getKey().size() + &quot; entities to &quot; + publisher.getAuthorizedName() + &quot; at node &quot; + getNode() + &quot; from source &quot; + sourceNode);</span>
<span class="nc" id="L307"> replicationClient.transferCustody(transferCustody);</span>
<span class="nc" id="L308"> } catch (DispositionReportFaultMessage df) {</span>
<span class="nc" id="L309"> logger.error(&quot;Unable to transfer entities from &quot; + sourceNode + &quot; to node &quot; + getNode() + &quot; to user &quot; + publisher.getAuthorizedName(), df);</span>
<span class="nc" id="L310"> throw new TransferNotAllowedException(new ErrorMessage(&quot;E_transferBlocked&quot;, df.getMessage()));</span>
<span class="nc" id="L311"> } catch (Exception ex) {</span>
<span class="nc" id="L312"> logger.error(&quot;Unable to transfer entities from &quot; + sourceNode + &quot; to node &quot; + getNode() + &quot; to user &quot; + publisher.getAuthorizedName(), ex);</span>
<span class="nc" id="L313"> throw new TransferNotAllowedException(new ErrorMessage(&quot;E_transferBlocked&quot;, ex.getMessage()));</span>
<span class="nc" id="L314"> }</span>
<span class="nc" id="L316"> } else {</span>
<span class="fc" id="L317"> changes.addAll(executeTransfer(body, em, publisher.getAuthorizedName(), getNode()));</span>
//all of the items to be transfer are owned locally by *this node.
}
<span class="fc" id="L321"> tx.commit();</span>
//we need to do something for replication purposes here
//enqueue notifications and storage of the changed records
<span class="fc bfc" id="L324" title="All 2 branches covered."> for (ChangeRecord c : changes) {</span>
try {
<span class="fc" id="L326"> c.setChangeID(new ChangeRecordIDType());</span>
<span class="fc" id="L327"> c.getChangeID().setNodeID(getNode());</span>
<span class="fc" id="L328"> c.getChangeID().setOriginatingUSN(null);</span>
<span class="fc" id="L329"> ReplicationNotifier.enqueue(MappingApiToModel.mapChangeRecord(c));</span>
<span class="nc" id="L330"> } catch (UnsupportedEncodingException ex) {</span>
<span class="nc" id="L331"> logger.error(&quot;&quot;, ex);</span>
<span class="fc" id="L332"> }</span>
<span class="fc" id="L333"> }</span>
<span class="fc" id="L334"> long procTime = System.currentTimeMillis() - startTime;</span>
<span class="fc" id="L335"> serviceCounter.update(CustodyTransferQuery.TRANSFER_ENTITIES,</span>
QueryStatus.SUCCESS, procTime);
} finally {
<span class="pc bpc" id="L339" title="3 of 4 branches missed."> if (tx.isActive()) {</span>
<span class="nc" id="L340"> tx.rollback();</span>
}
<span class="pc" id="L342"> em.close();</span>
<span class="fc" id="L343"> }</span>
<span class="fc" id="L345"> }</span>
private synchronized UDDIReplicationPortType getReplicationClient(String node) {
<span class="nc" id="L349"> UDDIService svc = new UDDIService();</span>
<span class="nc" id="L350"> UDDIReplicationPortType replicationClient = svc.getUDDIReplicationPort();</span>
<span class="nc" id="L352"> EntityManager em = PersistenceManager.getEntityManager();</span>
<span class="nc" id="L353"> EntityTransaction tx = em.getTransaction();</span>
try {
<span class="nc" id="L355"> StringBuilder sql = new StringBuilder();</span>
<span class="nc" id="L356"> sql.append(&quot;select c from ReplicationConfiguration c order by c.serialNumber desc&quot;);</span>
<span class="nc" id="L357"> sql.toString();</span>
<span class="nc" id="L358"> Query qry = em.createQuery(sql.toString());</span>
<span class="nc" id="L359"> qry.setMaxResults(1);</span>
<span class="nc" id="L361"> org.apache.juddi.model.ReplicationConfiguration resultList = (org.apache.juddi.model.ReplicationConfiguration) qry.getSingleResult();</span>
<span class="nc bnc" id="L362" title="All 2 branches missed."> for (Operator o : resultList.getOperator()) {</span>
<span class="nc bnc" id="L363" title="All 2 branches missed."> if (o.getOperatorNodeID().equalsIgnoreCase(node)) {</span>
<span class="nc" id="L364"> ((BindingProvider) replicationClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, o.getSoapReplicationURL());</span>
<span class="nc" id="L366"> return replicationClient;</span>
}
<span class="nc" id="L368"> }</span>
<span class="nc" id="L369"> tx.rollback();</span>
<span class="nc" id="L371"> } catch (Exception ex) {</span>
<span class="nc" id="L372"> logger.fatal(&quot;Node not found (or there isn't a replication config)!&quot; + node, ex);</span>
} finally {
<span class="nc bnc" id="L374" title="All 8 branches missed."> if (tx.isActive()) {</span>
<span class="nc" id="L375"> tx.rollback();</span>
}
<span class="nc" id="L377"> em.close();</span>
<span class="nc" id="L378"> }</span>
//em.close();
<span class="nc" id="L380"> return null;</span>
}
/**
* used to factor out the actual execution of custody transfer, used by
* both this service and the replication service.
*
* @since 3.3
* @param body
* @param em
* @param transferToPublisher
* @param transferToNode
* @return
* @throws DispositionReportFaultMessage
*/
protected List&lt;ChangeRecord&gt; executeTransfer(TransferEntities body, EntityManager em, String transferToPublisher, String transferToNode) throws DispositionReportFaultMessage {
// Once validated, the ownership transfer is as simple as switching the publisher
<span class="fc" id="L398"> List&lt;ChangeRecord&gt; changes = new ArrayList&lt;ChangeRecord&gt;();;</span>
<span class="fc" id="L399"> KeyBag keyBag = body.getKeyBag();</span>
<span class="fc" id="L400"> List&lt;String&gt; keyList = keyBag.getKey();</span>
//used for the change journal
<span class="fc bfc" id="L403" title="All 2 branches covered."> for (String key : keyList) {</span>
<span class="fc" id="L404"> UddiEntity uddiEntity = em.find(UddiEntity.class, key);</span>
<span class="fc" id="L405"> uddiEntity.setAuthorizedName(transferToPublisher);</span>
<span class="fc" id="L406"> uddiEntity.setNodeId(transferToNode);</span>
<span class="fc" id="L407"> Date now = new Date();</span>
<span class="fc" id="L408"> uddiEntity.setModified(now);</span>
<span class="fc" id="L409"> uddiEntity.setModifiedIncludingChildren(now);</span>
<span class="pc bpc" id="L411" title="1 of 2 branches missed."> if (uddiEntity instanceof BusinessEntity) {</span>
<span class="fc" id="L412"> BusinessEntity be = (BusinessEntity) uddiEntity;</span>
<span class="fc" id="L414"> List&lt;BusinessService&gt; bsList = be.getBusinessServices();</span>
<span class="pc bpc" id="L415" title="1 of 2 branches missed."> for (BusinessService bs : bsList) {</span>
<span class="nc" id="L416"> bs.setAuthorizedName(transferToPublisher);</span>
<span class="nc" id="L417"> bs.setNodeId(transferToNode);</span>
<span class="nc" id="L418"> bs.setModified(now);</span>
<span class="nc" id="L419"> bs.setModifiedIncludingChildren(now);</span>
<span class="nc" id="L421"> List&lt;BindingTemplate&gt; btList = bs.getBindingTemplates();</span>
<span class="nc bnc" id="L422" title="All 2 branches missed."> for (BindingTemplate bt : btList) {</span>
<span class="nc" id="L423"> bt.setAuthorizedName(transferToPublisher);</span>
<span class="nc" id="L424"> bt.setNodeId(transferToNode);</span>
<span class="nc" id="L425"> bt.setModified(now);</span>
<span class="nc" id="L426"> bt.setModifiedIncludingChildren(now);</span>
<span class="nc" id="L428"> }</span>
<span class="nc" id="L429"> }</span>
}
<span class="fc" id="L431"> ChangeRecord cr = new ChangeRecord();</span>
<span class="fc" id="L432"> cr.setChangeRecordNewData(new ChangeRecordNewData());</span>
<span class="fc" id="L433"> cr.getChangeRecordNewData().setOperationalInfo(new OperationalInfo());</span>
<span class="fc" id="L434"> cr.getChangeRecordNewData().getOperationalInfo().setAuthorizedName(transferToPublisher);</span>
<span class="fc" id="L435"> cr.getChangeRecordNewData().getOperationalInfo().setEntityKey(uddiEntity.getEntityKey());</span>
<span class="fc" id="L436"> cr.getChangeRecordNewData().getOperationalInfo().setNodeID(transferToNode);</span>
<span class="fc" id="L437"> GregorianCalendar gcal = new GregorianCalendar();</span>
<span class="fc" id="L438"> gcal.setTime(uddiEntity.getCreated());</span>
<span class="fc" id="L439"> cr.getChangeRecordNewData().getOperationalInfo().setCreated(df.newXMLGregorianCalendar(gcal));</span>
<span class="fc" id="L440"> gcal = new GregorianCalendar();</span>
<span class="fc" id="L441"> gcal.setTime(now);</span>
<span class="fc" id="L442"> cr.getChangeRecordNewData().getOperationalInfo().setModified(df.newXMLGregorianCalendar(gcal));</span>
<span class="fc" id="L443"> cr.getChangeRecordNewData().getOperationalInfo().setModifiedIncludingChildren(df.newXMLGregorianCalendar(gcal));</span>
<span class="fc" id="L444"> cr.getChangeRecordNewData().getOperationalInfo().setEntityKey(uddiEntity.getEntityKey());</span>
<span class="pc bpc" id="L446" title="1 of 2 branches missed."> if (uddiEntity instanceof BusinessEntity) {</span>
<span class="fc" id="L447"> cr.getChangeRecordNewData().setBusinessEntity(new org.uddi.api_v3.BusinessEntity());</span>
<span class="fc" id="L448"> MappingModelToApi.mapBusinessEntity((BusinessEntity) uddiEntity, cr.getChangeRecordNewData().getBusinessEntity());</span>
}
<span class="pc bpc" id="L450" title="1 of 2 branches missed."> if (uddiEntity instanceof Tmodel) {</span>
<span class="nc" id="L451"> cr.getChangeRecordNewData().setTModel(new org.uddi.api_v3.TModel());</span>
<span class="nc" id="L452"> MappingModelToApi.mapTModel((Tmodel) uddiEntity, cr.getChangeRecordNewData().getTModel());</span>
}
<span class="fc" id="L454"> changes.add(cr);</span>
<span class="fc" id="L455"> em.persist(uddiEntity);</span>
<span class="fc" id="L457"> }</span>
// After transfer is finished, the token can be removed
<span class="fc" id="L460"> org.uddi.custody_v3.TransferToken apiTransferToken = body.getTransferToken();</span>
String transferTokenId;
try {
<span class="fc" id="L463"> transferTokenId = new String(apiTransferToken.getOpaqueToken(), UTF8);</span>
<span class="nc" id="L464"> } catch (UnsupportedEncodingException ex) {</span>
<span class="nc" id="L465"> throw new InvalidValueException(new ErrorMessage(&quot;errors.stringEncoding&quot;));</span>
<span class="fc" id="L466"> }</span>
<span class="fc" id="L467"> org.apache.juddi.model.TransferToken modelTransferToken = em.find(org.apache.juddi.model.TransferToken.class, transferTokenId);</span>
<span class="fc" id="L468"> em.remove(modelTransferToken);</span>
<span class="fc" id="L469"> return changes;</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>