<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); 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 "AS IS" 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.
 */

#ifndef _ACTIVEMQ_CONNCETOR_STOMP_COMMANDS_ACKCOMMAND_H_
#define _ACTIVEMQ_CONNCETOR_STOMP_COMMANDS_ACKCOMMAND_H_

#include <activemq/connector/stomp/commands/AbstractCommand.h>
#include <activemq/connector/stomp/commands/CommandConstants.h>
#include <activemq/transport/Command.h>

namespace activemq{
namespace connector{
namespace stomp{
namespace commands{

    /**
     * Stomp Command that Represents Acknowledgement of a message
     * receive.  The Ack Command has one required attribute, message
     * Id.  For each message sent to the client from the broker, the
     * message will not be considered consumed until an Ack is sent.  
     * Optionally a Transaction Id can be set that indicates that the
     * message acknowledgement should be part of a named transaction.
     */
    class AckCommand : public AbstractCommand< transport::Command >
    {
    public:

        AckCommand(void) :
            AbstractCommand<transport::Command>() {
                initialize( getFrame() );
        }
        AckCommand( StompFrame* frame ) : 
            AbstractCommand<transport::Command>( frame ) {
                validate( getFrame() );
        }
        virtual ~AckCommand(void) {}
      
        /**
         * Get the Message Id of this Command
         * @return the Id of the Message
         */      
        virtual std::string getMessageId(void) const{
            return getPropertyValue( 
                CommandConstants::toString( 
                    CommandConstants::HEADER_MESSAGEID ), "" );
        }
      
        /**
         * Set the Message Id that this Ack is associated with
         * @param messageId the Message Id
         */
        virtual void setMessageId( const std::string& messageId ){
            setPropertyValue( 
                CommandConstants::toString( 
                    CommandConstants::HEADER_MESSAGEID ),
                messageId );
        }

    protected:
    
        /**
         * Inheritors are required to override this method to init the
         * frame with data appropriate for the command type.
         * @param frame Frame to init
         */
        virtual void initialize( StompFrame& frame )
        {
            frame.setCommand( CommandConstants::toString(
                CommandConstants::ACK ) );
        }

        /**
         * Inheritors are required to override this method to validate 
         * the passed stomp frame before it is marshalled or unmarshaled
         * @param frame Frame to validate
         * @returns true if frame is valid
         */
        virtual bool validate( const StompFrame& frame ) const
        {
            if((frame.getCommand() == 
                CommandConstants::toString( CommandConstants::ACK )) &&
               (frame.getProperties().hasProperty(
                   CommandConstants::toString( 
                       CommandConstants::HEADER_TRANSACTIONID ) ) &&
               (frame.getProperties().hasProperty(
                   CommandConstants::toString( 
                       CommandConstants::HEADER_MESSAGEID ) ) ) ) );
            {
                return true;
            }
<commit_msg>AMQ-1011 - fixing empty if clause in ACK command<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); 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 "AS IS" 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.
 */

#ifndef _ACTIVEMQ_CONNCETOR_STOMP_COMMANDS_ACKCOMMAND_H_
#define _ACTIVEMQ_CONNCETOR_STOMP_COMMANDS_ACKCOMMAND_H_

#include <activemq/connector/stomp/commands/AbstractCommand.h>
#include <activemq/connector/stomp/commands/CommandConstants.h>
#include <activemq/transport/Command.h>

namespace activemq{
namespace connector{
namespace stomp{
namespace commands{

    /**
     * Stomp Command that Represents Acknowledgement of a message
     * receive.  The Ack Command has one required attribute, message
     * Id.  For each message sent to the client from the broker, the
     * message will not be considered consumed until an Ack is sent.  
     * Optionally a Transaction Id can be set that indicates that the
     * message acknowledgement should be part of a named transaction.
     */
    class AckCommand : public AbstractCommand< transport::Command >
    {
    public:

        AckCommand(void) :
            AbstractCommand<transport::Command>() {
                initialize( getFrame() );
        }
        AckCommand( StompFrame* frame ) : 
            AbstractCommand<transport::Command>( frame ) {
                validate( getFrame() );
        }
        virtual ~AckCommand(void) {}
      
        /**
         * Get the Message Id of this Command
         * @return the Id of the Message
         */      
        virtual std::string getMessageId(void) const{
            return getPropertyValue( 
                CommandConstants::toString( 
                    CommandConstants::HEADER_MESSAGEID ), "" );
        }
      
        /**
         * Set the Message Id that this Ack is associated with
         * @param messageId the Message Id
         */
        virtual void setMessageId( const std::string& messageId ){
            setPropertyValue( 
                CommandConstants::toString( 
                    CommandConstants::HEADER_MESSAGEID ),
                messageId );
        }

    protected:
    
        /**
         * Inheritors are required to override this method to init the
         * frame with data appropriate for the command type.
         * @param frame Frame to init
         */
        virtual void initialize( StompFrame& frame )
        {
            frame.setCommand( CommandConstants::toString(
                CommandConstants::ACK ) );
        }

        /**
         * Inheritors are required to override this method to validate 
         * the passed stomp frame before it is marshalled or unmarshaled
         * @param frame Frame to validate
         * @returns true if frame is valid
         */
        virtual bool validate( const StompFrame& frame ) const
        {
            // Make sure the message is an ACK message.
            bool isAck = frame.getCommand() == 
                CommandConstants::toString( CommandConstants::ACK );
                
            // Make sure it has a transaction ID header.
            bool hasTransactionId = frame.getProperties().hasProperty(
                   CommandConstants::toString( 
                       CommandConstants::HEADER_TRANSACTIONID ) );
                       
            // Make sure it has a message ID header.
            bool hasMessageId = frame.getProperties().hasProperty(
                   CommandConstants::toString( 
                       CommandConstants::HEADER_MESSAGEID ) );
            
            if( isAck && hasTransactionId && hasMessageId )
            {
                return true;
            }

{'fraction_non_alphanumeric': 0.0693655589123867, 'fraction_numerical': 0.0014501510574018127, 'mean_word_length': 2.1230188679245283, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3835650', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1928, 'n_words': 713}