package org.hive2hive.core.processes.register;

import java.io.IOException;
import java.security.GeneralSecurityException;

import org.hive2hive.core.H2HConstants;
import org.hive2hive.core.exceptions.PutFailedException;
import org.hive2hive.core.model.versioned.EncryptedNetworkContent;
import org.hive2hive.core.network.data.DataManager;
import org.hive2hive.core.processes.common.base.BasePutProcessStep;
import org.hive2hive.core.processes.context.RegisterProcessContext;
import org.hive2hive.processframework.exceptions.InvalidProcessStateException;
import org.hive2hive.processframework.exceptions.ProcessExecutionException;

/**
 * @author Seppi
 */
public class PutUserProfileStep extends BasePutProcessStep {

	private final RegisterProcessContext context;

	public PutUserProfileStep(RegisterProcessContext context, DataManager dataManager) {
		super(dataManager);
		this.setName(getClass().getName());
		this.context = context;
	}

	@Override
	protected Void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
		try {
			EncryptedNetworkContent encrypted = dataManager.getEncryption().encryptAES(context.consumeUserProfile(),
					context.consumeUserProfileEncryptionKeys());
			encrypted.generateVersionKey();
			put(context.consumeUserProflieLocationKey(), H2HConstants.USER_PROFILE, encrypted,
					context.consumeUserProfileProtectionKeys());
		} catch (PutFailedException ex) {
			throw new ProcessExecutionException(this, ex);
		} catch (GeneralSecurityException | IllegalStateException | IOException ex) {
			throw new ProcessExecutionException(this, ex, String.format("Cannot encrypt the user profile."));
		}
		return null;
	}

}

@@ -623,16 +623,73 @@
 ception;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0A/**%0A *
@@ -769,16 +769,105 @@
 Step %7B%0A%0A
+%09private static final Logger logger = LoggerFactory.getLogger(PutUserProfileStep.class);%0A
 %09private
@@ -1194,16 +1194,114 @@
 %09%09try %7B%0A
+%09%09%09logger.debug(%22Start encrypting the user profile of the new user %7B%7D%22, context.consumeUserId());%0A
 %09%09%09Encry
@@ -1485,16 +1485,93 @@
 nKey();%0A
+%09%09%09logger.debug(%22User profile successfully encrypted. Start putting it...%22);%0A
 %09%09%09put(c
@@ -1704,90 +1704,20 @@
 ;%0A%09%09
-%7D catch (PutFailedException ex) %7B%0A%09%09%09throw new ProcessExecutionException(this, ex)
+%09return null
 ;%0A%09%09
@@ -1794,16 +1794,112 @@
 n ex) %7B%0A
+%09%09%09logger.error(%22Cannot encrypt the user profile of the new user %7B%7D%22, context.consumeUserId());%0A
 %09%09%09throw
@@ -1943,22 +1943,8 @@
 ex, 
-String.format(
 %22Can
@@ -1978,29 +1978,191 @@
 e.%22)
-)
 ;%0A%09%09%7D
-%0A%09%09return null;
+ catch (PutFailedException ex) %7B%0A%09%09%09logger.error(%22Cannot put the user profile of the new user %7B%7D%22, context.consumeUserId());%0A%09%09%09throw new ProcessExecutionException(this, ex);%0A%09%09%7D
 %0A%09%7D%0A

Add logging output to PutUserProfileStep