Commit a5b390ea authored by Romain Bioteau's avatar Romain Bioteau Committed by benjaminParisel

fix(workspace) delete metadata properly when embedded in Studio (#2724)

* fix aspect on delete

Closes UID-100
parent 98fe047c
......@@ -223,4 +223,8 @@ public abstract class AbstractRepository<T extends Identifiable> implements Repo
throw new RepositoryException(format("Failed to gerenrate object ID"), e);
}
}
public JsonFileBasedPersister<T> getPersister() {
return persister;
}
}
......@@ -14,6 +14,7 @@
*/
package org.bonitasoft.web.designer.studio.repository;
import java.io.IOException;
import java.nio.file.Path;
import javax.inject.Inject;
......@@ -23,9 +24,10 @@ import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.bonitasoft.web.designer.model.Identifiable;
import org.bonitasoft.web.designer.repository.AbstractRepository;
import org.bonitasoft.web.designer.repository.JsonFileBasedPersister;
import org.bonitasoft.web.designer.repository.Repository;
import org.bonitasoft.web.designer.repository.exception.RepositoryException;
import org.bonitasoft.web.designer.studio.workspace.LockedResourceException;
import org.bonitasoft.web.designer.studio.workspace.ResourceNotFoundException;
import org.bonitasoft.web.designer.studio.workspace.WorkspaceResourceHandler;
import org.springframework.context.annotation.Profile;
......@@ -48,21 +50,6 @@ public class RepositoryAspect {
this.handler = handler;
}
/*
* BS-14120
* Useless numerous notfications may lead to a localized studio crash,
* we decided to deactivate them until we find a proper solution for
* workspace management shared between studio and UIDesigner
*/
//@Before("execution(* org.bonitasoft.web.designer.repository.Repository+.get(String))")
public void preOpen(JoinPoint joinPoint) {
try {
handler.preOpen(filePath(joinPoint));
} catch (ResourceNotFoundException | LockedResourceException e) {
throw new RepositoryException("An error occured while proceeding pre open action.", e);
}
}
@After("execution(* org.bonitasoft.web.designer.repository.Repository+.updateLastUpdateAndSave(..)) ")
public void postSaveAndUpdateDate(JoinPoint joinPoint) {
try {
......@@ -80,8 +67,10 @@ public class RepositoryAspect {
@Around("execution(* org.bonitasoft.web.designer.repository.AbstractRepository.delete(String))")
public void delete(JoinPoint joinPoint) {
try {
Object component = get(joinPoint);
handler.delete(filePath(joinPoint));
} catch (ResourceNotFoundException e) {
getPersister(joinPoint).delete(resolvePathFolder(joinPoint), (Identifiable) component);
} catch (ResourceNotFoundException | IOException e) {
throw new RepositoryException("An error occured while proceeding delete action.", e);
}
}
......@@ -98,6 +87,18 @@ public class RepositoryAspect {
private Path filePath(JoinPoint joinPoint) {
return ((Repository<?>) joinPoint.getThis()).resolvePath(artifactId(joinPoint));
}
private Path resolvePathFolder(JoinPoint joinPoint) {
return ((Repository<?>) joinPoint.getThis()).resolvePathFolder(artifactId(joinPoint));
}
private Identifiable get(JoinPoint joinPoint){
return ((Repository<?>) joinPoint.getThis()).get(artifactId(joinPoint));
}
private JsonFileBasedPersister getPersister(JoinPoint joinPoint){
return ((AbstractRepository) joinPoint.getThis()).getPersister();
}
private String artifactId(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
......
......@@ -104,7 +104,7 @@ public class RepositoryAspectTest {
@Test
public void should_trigger_delete_on_workspaceResourceHandler_when_deleting_a_widget() throws Exception {
widgetRepository.save(aWidget().id("widgetId1").build());
widgetRepository.save(aWidget().id("widgetId1").custom().build());
widgetRepository.delete("widgetId1");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment