package com.specmate.emfrest.crud;

import javax.ws.rs.core.Response;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import com.specmate.auth.api.IAuthenticationService;
import com.specmate.common.RestResult;
import com.specmate.common.SpecmateException;
import com.specmate.emfrest.api.IRestService;
import com.specmate.emfrest.api.RestServiceBase;
import com.specmate.model.support.util.SpecmateEcoreUtil;

@Component(immediate = true, service = IRestService.class)
public class DeleteService extends RestServiceBase {
	private IAuthenticationService authService;

	@Override
	public String getServiceName() {
		return "delete";
	}

	@Override
	public boolean canDelete(Object target) {
		return (target instanceof EObject) && !(target instanceof Resource);
	}

	@Override
	public RestResult<?> delete(Object target, String token) throws SpecmateException {
		if (target instanceof EObject && !(target instanceof Resource)) {
			SpecmateEcoreUtil.detach((EObject) target);
			return new RestResult<>(Response.Status.OK, target, authService.getUserName(token));
		} else {
			throw new SpecmateException("Attempt to delete non EObject");
		}
	}

	@Reference
	public void setAuthService(IAuthenticationService authService) {
		this.authService = authService;
	}

}

@@ -35,45 +35,8 @@
 %0D%0A%0D%0A
-import javax.ws.rs.core.Response;%0D%0A%0D%0A
 impo
@@ -66,24 +66,24 @@
 e.EObject;%0D%0A
+
 import org.e
@@ -478,67 +478,8 @@
 se;%0D
-%0Aimport com.specmate.model.support.util.SpecmateEcoreUtil;%0D
 %0A%0D%0A@
@@ -950,293 +950,71 @@
 %0D%0A%09%09
-if (target instanceof EObject && !(target instanceof Resource)) %7B%0D%0A%09%09%09SpecmateEcoreUtil.detach((EObject) target);%0D%0A%09%09%09return new RestResult%3C%3E(Response.Status.OK, target, authService.getUserName(token));%0D%0A%09%09%7D else %7B%0D%0A%09%09%09throw new SpecmateException(%22Attempt to delete non EObject%22);%0D%0A%09%09%7D
+return CrudUtil.delete(target, authService.getUserName(token));
 %0D%0A%09%7D

add delete service