package info.elexis.server.core.p2.jaxrs;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.operations.Update;
import org.osgi.service.component.annotations.Component;

import info.elexis.server.core.p2.internal.ProvisioningHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = { "p2" })
@Path("p2")
@Component(service = UpdateResource.class, immediate = true)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public class UpdateResource {

	@GET
	@Path("updates")
	@ApiOperation(nickname = "checkUpdate", value = "check for available updates")
	public Response checkUpdates() {
		List<String> resultList = new ArrayList<>();
		Update[] possibleUpdates = ProvisioningHelper.getPossibleUpdates();
		if (possibleUpdates != null) {
			for (Update update : possibleUpdates) {
				resultList.add(update.toString());
			}
		}
		return Response.ok(resultList).build();
	}
	
	@POST
	@Path("updates")
	@ApiOperation(nickname = "executeUpdate", value = "check for available updates")
	public Response executeUpdates() {
		IStatus updateAllFeatures = ProvisioningHelper.updateAllFeatures();
		if(updateAllFeatures.isOK()) {
			return Response.ok().build();
		}
		return Response.ok().build();
	}

}

@@ -81,20 +81,81 @@
 va.util.
-List
+Arrays;%0Aimport java.util.List;%0Aimport java.util.stream.Collectors
 ;%0A%0Aimpor
@@ -950,55 +950,8 @@
 ) %7B%0A
-%09%09List%3CString%3E resultList = new ArrayList%3C%3E();%0A
 %09%09Up
@@ -1022,116 +1022,94 @@
 ;%0A%09%09
-if (possibleUpdates != null) %7B%0A%09%09%09for (Update update : possibleUpdates) %7B%0A%09%09%09%09resultList.add(u
+List%3CString%3E resultList = Arrays.asList(possibleUpdates).stream().map(U
 pdate
-.
+::
 toString
 ());
@@ -1108,21 +1108,44 @@
 ring
-());%0A%09%09%09%7D%0A%09%09%7D
+)%0A%09%09%09%09.collect(Collectors.toList());
 %0A%09%09r
@@ -1190,10 +1190,9 @@
 %0A%09%7D%0A
-%09
 %0A
+
 %09@PO
@@ -1404,12 +1404,13 @@
 ();%0A
-
 %09%09if
+ 
 (upd

Add base update post rest operation