/*
 * This file is part of Report Portal.
 *
 * Report Portal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Report Portal is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with Report Portal.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.epam.ta.reportportal;

import com.epam.ta.reportportal.database.BinaryData;
import com.epam.ta.reportportal.database.DataStorage;
import com.epam.ta.reportportal.database.Time;
import com.mongodb.gridfs.GridFSDBFile;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * Simple file storage.
 *
 * @author Andrei Varabyeu
 */
class InMemoryStorageMock implements DataStorage {

	private Map<DataKey, BinaryData> inMemoryStorage = new ConcurrentHashMap<>();

	static class DataKey {
		String filename;
		String id;

		public DataKey(String filename, String id) {
			this.filename = filename;
			this.id = id;
		}

	}

	@Override
	public String saveData(BinaryData data, String filename) {
		String id = UUID.randomUUID().toString();
		inMemoryStorage.put(new DataKey(filename, id), data);
		return id;
	}

	@Override
	@Deprecated
	public BinaryData fetchData(String filename) {
		return inMemoryStorage.entrySet().stream().filter(e -> filename.equals(e.getKey().filename)).findAny().get().getValue();
	}

	@Override
	public List<BinaryData> findByFilename(String filename) {
		return inMemoryStorage.entrySet().stream().filter(e -> filename.equals(e.getKey().filename)).map(Map.Entry::getValue)
				.collect(Collectors.toList());
	}

	@Override
	public void deleteData(String dataId) {
		inMemoryStorage.entrySet().stream().filter(e -> dataId.equals(e.getKey().id)).map(Map.Entry::getKey)
				.forEach(k -> inMemoryStorage.remove(k));
	}

	@Override
	public void deleteAll() {
		inMemoryStorage.clear();

	}

	@Override
	public void delete(List<String> ids) {
		inMemoryStorage.entrySet().stream().filter(e -> ids.contains(e.getKey().id)).map(Map.Entry::getKey)
				.forEach(k -> inMemoryStorage.remove(k));
	}

	@Override
	public void deleteByFilename(String filename) {
		inMemoryStorage.entrySet().stream().filter(e -> filename.equals(e.getKey().filename)).map(Map.Entry::getKey)
				.forEach(k -> inMemoryStorage.remove(k));

	}

	@Override
	public List<GridFSDBFile> findModifiedLaterAgo(Time period, String project) {
		throw new UnsupportedOperationException("Not implemented");
	}

	@Override
	public String saveData(BinaryData binaryData, String filename, Map<String, String> metainfo) {
		return saveData(binaryData, filename);
	}

}

@@ -984,24 +984,50 @@
 a.util.Map;%0A
+import java.util.Objects;%0A
 import java.
@@ -1037,16 +1037,16 @@
 l.UUID;%0A
-
 import j
@@ -1470,16 +1470,372 @@
 d;%0A%09%09%7D%0A%0A
+%09%09@Override%0A%09%09public boolean equals(Object o) %7B%0A%09%09%09if (this == o)%0A%09%09%09%09return true;%0A%09%09%09if (o == null %7C%7C getClass() != o.getClass())%0A%09%09%09%09return false;%0A%09%09%09DataKey dataKey = (DataKey) o;%0A%09%09%09return Objects.equals(filename, dataKey.filename) && Objects.equals(id, dataKey.id);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public int hashCode() %7B%0A%09%09%09return Objects.hash(filename, id);%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Ov
@@ -2033,21 +2033,8 @@
 ide%0A
-%09@Deprecated%0A
 %09pub
@@ -2061,32 +2061,30 @@
 Data(String 
-filename
+dataId
 ) %7B%0A%09%09return
@@ -2111,32 +2111,37 @@
 rySet().stream()
+%0A%09%09%09%09
 .filter(e -%3E fil
@@ -2133,32 +2133,30 @@
 filter(e -%3E 
-filename
+dataId
 .equals(e.ge
@@ -2162,24 +2162,18 @@
 etKey().
-filename
+id
 )).findA
@@ -2181,23 +2181,44 @@
 y().
-get().getValue(
+map(Map.Entry::getValue).orElse(null
 );%0A%09

fix unit tests