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

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

import javax.ws.rs.GET;
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.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/check")
	@ApiOperation(nickname = "checkUpdates", 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();
	}

}

@@ -112,16 +112,41 @@
 rs.GET;%0A
+import javax.ws.rs.POST;%0A
 import j
@@ -162,16 +162,16 @@
 s.Path;%0A
-
 import j
@@ -261,16 +261,57 @@
 ponse;%0A%0A
+import org.eclipse.core.runtime.IStatus;%0A
 import o
@@ -581,17 +581,16 @@
 %0A@Path(%22
-/
 p2%22)%0A@Co
@@ -772,14 +772,8 @@
 ates
-/check
 %22)%0A%09
@@ -809,17 +809,16 @@
 ckUpdate
-s
 %22, value
@@ -1126,16 +1126,16 @@
 %09%09%7D%0A%09%09%7D%0A
-
 %09%09return
@@ -1170,12 +1170,332 @@
 ld();%0A%09%7D
+%0A%09%0A%09@POST%0A%09@Path(%22updates%22)%0A%09@ApiOperation(nickname = %22executeUpdate%22, value = %22check for available updates%22)%0A%09public Response executeUpdates() %7B%0A%09%09IStatus updateAllFeatures = ProvisioningHelper.updateAllFeatures();%0A%09%09if(updateAllFeatures.isOK()) %7B%0A%09%09%09return Response.ok().build();%0A%09%09%7D%0A%09%09return Response.ok().build();%0A%09%7D
 %0A%0A%7D%0A

Add base update post rest operation