Search in sources :

Example 1 with ResourceUpdatedEvent

use of org.uberfire.workbench.events.ResourceUpdatedEvent in project kie-wb-common by kiegroup.

the class ModuleRepositoriesSynchronizerTest method testAddAndRemoveModuleRepository.

@Test
public void testAddAndRemoveModuleRepository() {
    final ResourceUpdatedEvent event = new ResourceUpdatedEvent(pomPath, "", sessionInfo);
    final Set<ModuleRepositories.ModuleRepository> repositories = new HashSet<ModuleRepositories.ModuleRepository>() {

        {
            add(new ModuleRepositories.ModuleRepository(true, new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL)));
        }
    };
    final ModuleRepositories moduleRepositories = new ModuleRepositories(repositories);
    when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories);
    when(repositoryResolver.getRemoteRepositoriesMetaData(module)).thenReturn(new HashSet<MavenRepositoryMetadata>() {

        {
            add(new MavenRepositoryMetadata("remote-id", "remote-url", MavenRepositorySource.PROJECT));
        }
    });
    synchronizer.onResourceUpdated(event);
    final ArgumentCaptor<ModuleRepositories> moduleRepositoriesArgumentCaptor = ArgumentCaptor.forClass(ModuleRepositories.class);
    verify(moduleRepositoriesService, times(1)).save(eq(moduleRepositoriesPath), moduleRepositoriesArgumentCaptor.capture(), any(String.class));
    final ModuleRepositories saved = moduleRepositoriesArgumentCaptor.getValue();
    assertNotNull(saved);
    assertEquals(1, saved.getRepositories().size());
    final ModuleRepositories.ModuleRepository repository = saved.getRepositories().iterator().next();
    assertTrue(repository.isIncluded());
    assertEquals("remote-id", repository.getMetadata().getId());
    assertEquals("remote-url", repository.getMetadata().getUrl());
    assertEquals(MavenRepositorySource.PROJECT, repository.getMetadata().getSource());
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) ResourceUpdatedEvent(org.uberfire.workbench.events.ResourceUpdatedEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with ResourceUpdatedEvent

use of org.uberfire.workbench.events.ResourceUpdatedEvent in project kie-wb-common by kiegroup.

the class ResourceUpdatedEventAdapter method toSocial.

@Override
public SocialActivitiesEvent toSocial(Object object) {
    ResourceUpdatedEvent event = (ResourceUpdatedEvent) object;
    SocialUser socialUser = socialUserRepositoryAPI.findSocialUser(event.getSessionInfo().getIdentity().getIdentifier());
    String additionalInfo = "Edited";
    String description = getCommitDescription(event);
    return new SocialActivitiesEvent(socialUser, HomePageTypes.RESOURCE_UPDATE_EVENT.name(), new Date()).withLink(event.getPath().getFileName(), event.getPath().toURI()).withAdicionalInfo(additionalInfo).withDescription(description);
}
Also used : SocialUser(org.ext.uberfire.social.activities.model.SocialUser) SocialActivitiesEvent(org.ext.uberfire.social.activities.model.SocialActivitiesEvent) ResourceUpdatedEvent(org.uberfire.workbench.events.ResourceUpdatedEvent) Date(java.util.Date)

Example 3 with ResourceUpdatedEvent

use of org.uberfire.workbench.events.ResourceUpdatedEvent in project kie-wb-common by kiegroup.

the class ResourceUpdatedEventAdapter method isASystemEvent.

private boolean isASystemEvent(Object _event) {
    ResourceUpdatedEvent event = (ResourceUpdatedEvent) _event;
    final String user = event.getSessionInfo().getIdentity().getIdentifier();
    if (user.equalsIgnoreCase("system") || user.equalsIgnoreCase("<system>")) {
        return true;
    }
    return false;
}
Also used : ResourceUpdatedEvent(org.uberfire.workbench.events.ResourceUpdatedEvent)

Example 4 with ResourceUpdatedEvent

use of org.uberfire.workbench.events.ResourceUpdatedEvent in project kie-wb-common by kiegroup.

the class ModuleRepositoriesSynchronizerTest method testAddModuleRepository.

@Test
public void testAddModuleRepository() {
    final ResourceUpdatedEvent event = new ResourceUpdatedEvent(pomPath, "", sessionInfo);
    final ModuleRepositories moduleRepositories = new ModuleRepositories();
    when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories);
    when(repositoryResolver.getRemoteRepositoriesMetaData(module)).thenReturn(new HashSet<MavenRepositoryMetadata>() {

        {
            add(new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL));
        }
    });
    synchronizer.onResourceUpdated(event);
    final ArgumentCaptor<ModuleRepositories> moduleRepositoriesArgumentCaptor = ArgumentCaptor.forClass(ModuleRepositories.class);
    verify(moduleRepositoriesService, times(1)).save(eq(moduleRepositoriesPath), moduleRepositoriesArgumentCaptor.capture(), any(String.class));
    final ModuleRepositories saved = moduleRepositoriesArgumentCaptor.getValue();
    assertNotNull(saved);
    assertEquals(1, saved.getRepositories().size());
    final ModuleRepositories.ModuleRepository repository = saved.getRepositories().iterator().next();
    assertTrue(repository.isIncluded());
    assertEquals("local-id", repository.getMetadata().getId());
    assertEquals("local-url", repository.getMetadata().getUrl());
    assertEquals(MavenRepositorySource.LOCAL, repository.getMetadata().getSource());
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) ResourceUpdatedEvent(org.uberfire.workbench.events.ResourceUpdatedEvent) Test(org.junit.Test)

Example 5 with ResourceUpdatedEvent

use of org.uberfire.workbench.events.ResourceUpdatedEvent in project kie-wb-common by kiegroup.

the class ModuleRepositoriesSynchronizerTest method testRemoveModuleRepository.

@Test
public void testRemoveModuleRepository() {
    final ResourceUpdatedEvent event = new ResourceUpdatedEvent(pomPath, "", sessionInfo);
    final Set<ModuleRepositories.ModuleRepository> repositories = new HashSet<ModuleRepositories.ModuleRepository>() {

        {
            add(new ModuleRepositories.ModuleRepository(true, new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL)));
        }
    };
    final ModuleRepositories moduleRepositories = new ModuleRepositories(repositories);
    when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories);
    synchronizer.onResourceUpdated(event);
    final ArgumentCaptor<ModuleRepositories> moduleRepositoriesArgumentCaptor = ArgumentCaptor.forClass(ModuleRepositories.class);
    verify(moduleRepositoriesService, times(1)).save(eq(moduleRepositoriesPath), moduleRepositoriesArgumentCaptor.capture(), any(String.class));
    final ModuleRepositories saved = moduleRepositoriesArgumentCaptor.getValue();
    assertNotNull(saved);
    assertEquals(0, saved.getRepositories().size());
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) ResourceUpdatedEvent(org.uberfire.workbench.events.ResourceUpdatedEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ResourceUpdatedEvent (org.uberfire.workbench.events.ResourceUpdatedEvent)5 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)3 ModuleRepositories (org.guvnor.common.services.project.model.ModuleRepositories)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 Date (java.util.Date)1 SocialActivitiesEvent (org.ext.uberfire.social.activities.model.SocialActivitiesEvent)1 SocialUser (org.ext.uberfire.social.activities.model.SocialUser)1