/**
 * Copyright 2008-2009 DRIVER PROJECT (ICM UW)
 * Original author: Marek Horst
 *
 * 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.
 */
package eu.dnetlib.data.ismock;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import eu.dnetlib.common.profile.Profile;
import eu.dnetlib.common.profile.ProfileHeader;
import eu.dnetlib.data.index.ws.commons.profile.utils.IndexProfileMarshaller;
import eu.dnetlib.data.index.ws.commons.profile.utils.IndexProfileUnMarshaller;


/**
 * MockDataContainer for IS-PR and IS-LU purposes.
 * 
 * @author mhorst
 * 
 */
public class MockDataContainer {

	Map<String, String> profiles = new HashMap<String, String>();

	public String registerProfile(String resourceProfile) {
		String genId = String.valueOf(System.currentTimeMillis());

		// currently resourceIdentifier is set to IndexDSResourceType profiles
		// only
		if (resourceProfile.contains(ProfileHeader.INDEX_DS_RESOURCE_TYPE)) {
			Profile indexProfile = IndexProfileUnMarshaller
					.unmarshallIndexResource(resourceProfile);
			indexProfile.getHeader().setResourceIdentifier(genId);
			resourceProfile = IndexProfileMarshaller
					.generateIndexProfile(indexProfile);
		}
		profiles.put(genId, resourceProfile);
		return genId;
	}
	
	public boolean deleteProfile(String profId) {
		profiles.remove(profId);
		return true;
	}

	public boolean updateProfile(String profId, String resourceProfile,
			String resourceType) {
		profiles.put(profId, resourceProfile);
		return true;
	}
	
	public String getResourceProfile(String profId) {
		return profiles.get(profId);
	}
	
	public Set<String> getAllProfilesIds() {
		return profiles.keySet();
	}
}
