package com.drumonii.loltrollbuild.rest.processor;

import com.drumonii.loltrollbuild.model.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.ResourceProcessor;
import org.springframework.stereotype.Component;

/**
 * {@link ResourceProcessor} to add only a single self {@link Link} to a {@link Item} {@link Resource}.
 */
@Component
public class ItemResourceProcessor implements ResourceProcessor<Resource<Item>> {

	@Autowired
	private RepositoryEntityLinks repositoryEntityLinks;

	@Override
	public Resource<Item> process(Resource<Item> resource) {
		return new Resource<>(resource.getContent(),
				repositoryEntityLinks.linkToSingleResource(Item.class, resource.getContent().getId())
						.withSelfRel());
	}

}

@@ -45,16 +45,65 @@
 essor;%0A%0A
+import com.drumonii.loltrollbuild.model.GameMap;%0A
 import c
@@ -140,16 +140,16 @@
 l.Item;%0A
-
 import o
@@ -319,16 +319,58 @@
 s.Link;%0A
+import org.springframework.hateoas.Links;%0A
 import o
@@ -510,16 +510,126 @@
 onent;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.stream.Collectors;%0A%0A
 /**%0A * %7B
@@ -968,57 +968,811 @@
 %7B%0A%09%09
-return new Resource%3C%3E(resource.getContent(),%0A%09%09%09%09
+List%3CLink%3E links = new ArrayList%3C%3E();%0A%09%09if (!resource.getContent().getFrom().isEmpty()) %7B%0A%09%09%09links.addAll(resource.getContent().getFrom().stream()%0A%09%09%09%09%09.map(from -%3E repositoryEntityLinks.linkToSingleResource(Item.class, from)%0A%09%09%09%09%09%09%09.withRel(%22from%22))%0A%09%09%09%09%09.collect(Collectors.toList()));%0A%09%09%7D%0A%09%09if (!resource.getContent().getInto().isEmpty()) %7B%0A%09%09%09links.addAll(resource.getContent().getInto().stream()%0A%09%09%09%09%09.map(into -%3E repositoryEntityLinks.linkToSingleResource(Item.class, into)%0A%09%09%09%09%09%09%09.withRel(%22into%22))%0A%09%09%09%09%09.collect(Collectors.toList()));%0A%09%09%7D%0A%09%09links.addAll(resource.getContent().getMaps().entrySet().stream()%0A%09%09%09%09.filter(Map.Entry::getValue)%0A%09%09%09%09.map(entry -%3E repositoryEntityLinks.linkToSingleResource(GameMap.class, entry.getKey()).withRel(%22maps%22))%0A%09%09%09%09.collect(Collectors.toList()));%0A%09%09links.add(
 repo
@@ -1853,26 +1853,24 @@
 etId())%0A%09%09%09%09
-%09%09
 .withSelfRel
@@ -1874,14 +1874,80 @@
 Rel());%0A
+%09%09return new Resource%3C%3E(resource.getContent(), new Links(links));%0A
 %09%7D%0A%0A%7D%0A

Add into, from, and maps links to the Items API response