/*******************************************************************************
 * Copyright (c) 2017 Universitat Politécnica de Catalunya (UPC)
 *
 * Licensed 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.
 *
 * Contributors: Edith Zavala
 *******************************************************************************/

package org.loopa.element.messagecomposer.dataformatter;

import java.util.Arrays;
import java.util.Map;
import org.loopa.comm.message.IMessage;
import org.loopa.comm.message.Message;

public class DataFormatter extends ADataFormatter {

  @Override
  public void processMessage(IMessage t) {
    String recipientsReqSpecialFormat = getRecipientFromPolicy(t.getMessageBody());
    if (recipientsReqSpecialFormat != null) {
      Arrays.stream(recipientsReqSpecialFormat.split(":")).forEach(r -> {
        Map<String, String> formattedMessageBody = formatMessageContent(t.getMessageBody(), r);
        createMeassage(new Message(t.getMessageFrom(), t.getMessageTo(), t.getMessageCode(),
            t.getMessageType(), formattedMessageBody));
      });
    } else {
      createMeassage(new Message(t.getMessageFrom(), t.getMessageTo(), t.getMessageCode(),
          t.getMessageType(), t.getMessageBody()));
    }
  }

  protected Map<String, String> formatMessageContent(Map<String, String> m, String r) {
    return m;
  }

  protected String getRecipientFromPolicy(Map<String, String> messageContent) {
    return this.getPolicyVariables().get(messageContent.get("type"));
  }

  protected void createMeassage(IMessage formattedMessage) {
    this.getMessageCreator().processMessage(formattedMessage);

  }
}

@@ -1117,32 +1117,16 @@
 cipients
-ReqSpecialFormat
  = getRe
@@ -1182,32 +1182,16 @@
 cipients
-ReqSpecialFormat
  != null
@@ -1228,24 +1228,8 @@
 ents
-ReqSpecialFormat
 .spl
@@ -1516,257 +1516,295 @@
    %7D
- else %7B%0A      createMeassage(new Message(t.getMessageFrom(), t.getMessageTo(), t.getMessageCode(),%0A          t.getMessageType(), t.getMessageBody()));%0A    %7D%0A  %7D%0A%0A  protected Map%3CString, String%3E formatMessageContent(Map%3CString, String%3E m, String r) %7B
+%0A  %7D%0A%0A  protected Map%3CString, String%3E formatMessageContent(Map%3CString, String%3E m, String r) %7B%0A    /** check format required in policy if exist and format message */%0A    // change messageBody type for indicating a unique recipient%0A    m.put(%22type%22, (m.get(%22type%22)).concat(%22_%22).concat(r));
 %0A   

Update DataFormatter.java