Search in sources :

Example 1 with KProperty

use of org.uberfire.ext.metadata.model.KProperty in project kie-wb-common by kiegroup.

the class LibraryIndexer method toKObject.

@Override
public KObject toKObject(final Path path) {
    KObject index = null;
    try {
        // create a builder with the default information
        IndexBuilder builder = fillIndexBuilder(path);
        Set<KProperty<?>> indexElements = null;
        if (builder != null) {
            // build index document
            indexElements = builder.build();
        } else {
            indexElements = Collections.emptySet();
        }
        index = KObjectUtil.toKObject(path, LIBRARY_CLASSIFIER, indexElements);
    } catch (Exception e) {
        // Unexpected parsing or processing error
        logger.error("Unable to index '" + path.toUri().toString() + "'.", e.getMessage(), e);
    }
    return index;
}
Also used : KObject(org.uberfire.ext.metadata.model.KObject) KProperty(org.uberfire.ext.metadata.model.KProperty) IndexBuilder(org.kie.workbench.common.services.refactoring.backend.server.indexing.IndexBuilder)

Example 2 with KProperty

use of org.uberfire.ext.metadata.model.KProperty in project kie-wb-common by kiegroup.

the class SharedPart method toIndexElements.

@Override
public List<KProperty<?>> toIndexElements() {
    final List<KProperty<?>> indexElements = new ArrayList<>();
    // Impact Analysis reference
    ValueSharedPartIndexTerm sharedPartTerm = new ValueSharedPartIndexTerm(this.partName, this.partType);
    indexElements.add(new KPropertyImpl<>(sharedPartTerm.getTerm(), sharedPartTerm.getValue()));
    return indexElements;
}
Also used : ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) KProperty(org.uberfire.ext.metadata.model.KProperty) ArrayList(java.util.ArrayList)

Example 3 with KProperty

use of org.uberfire.ext.metadata.model.KProperty in project kie-wb-common by kiegroup.

the class BPMNProcessIdsResponseBuilder method testJBPM8828.

@Test
public void testJBPM8828() {
    final FindBpmnProcessIdsQuery findBpmnProcessIdsQuery = new FindBpmnProcessIdsQuery();
    final List<KObject> kObjects = new ArrayList<>();
    kObjects.add(kObject1);
    kObjects.add(kObject2);
    final List<KProperty<?>> kProperties1 = new ArrayList<>();
    kProperties1.add(kProperty1);
    final List<KProperty<?>> kProperties2 = new ArrayList<>();
    kProperties2.add(kProperty2);
    final String invalidFile = "ProcessA1";
    final String validFile = "ProcessB1";
    final URI validURI = URI.create(validFile);
    when(kObject1.getProperties()).thenReturn(kProperties1);
    when(kObject1.getKey()).thenReturn(invalidFile);
    when(kObject2.getProperties()).thenReturn(kProperties2);
    when(kObject2.getKey()).thenReturn(validFile);
    when(kProperty1.getName()).thenReturn(findBpmnProcessIdsQuery.getProcessIdResourceType().toString());
    when(kProperty1.getValue()).thenReturn(invalidFile);
    when(kProperty2.getName()).thenReturn(findBpmnProcessIdsQuery.getProcessIdResourceType().toString());
    when(kProperty2.getValue()).thenReturn(validFile);
    when(validPath.getFileName()).thenReturn(validPath);
    when(validPath.toUri()).thenReturn(validURI);
    when(validPath.getFileSystem()).thenReturn(fileSystem);
    String exceptionString = "FILE_SYSTEM_NOT_FOUND_EXCEPTION";
    when(exception.toString()).thenReturn(exceptionString);
    Set<String> attribViews = new HashSet<>();
    when(fileSystem.supportedFileAttributeViews()).thenReturn(attribViews);
    when(ioService.get(any(URI.class))).thenAnswer(new Answer<Path>() {

        public Path answer(InvocationOnMock invocation) throws FileSystemNotFoundException {
            Object[] args = invocation.getArguments();
            URI uri = (URI) args[0];
            if (uri.getPath().compareTo(invalidFile) == 0) {
                throw exception;
            }
            return validPath;
        }
    });
    AbstractFindIdsQuery.BpmnProcessIdsResponseBuilder responseBuilder = new AbstractFindIdsQuery.BpmnProcessIdsResponseBuilder(ioService, findBpmnProcessIdsQuery.getProcessIdResourceType());
    responseBuilder.LOGGER = logger;
    List<RefactoringPageRow> response = responseBuilder.buildResponse(kObjects);
    RefactoringPageRow pageRow = response.get(0);
    Map<String, Path> pageRowValue = (Map<String, Path>) pageRow.getValue();
    verify(logger, times(1)).error(exceptionString);
    assertEquals(1, response.size(), 0);
    assertEquals(1, pageRowValue.size(), 0);
    assertTrue(validPath.compareTo(pageRowValue.get(validFile)) == 0);
}
Also used : Path(org.uberfire.java.nio.file.Path) ArrayList(java.util.ArrayList) URI(java.net.URI) KObject(org.uberfire.ext.metadata.model.KObject) KProperty(org.uberfire.ext.metadata.model.KProperty) FileSystemNotFoundException(org.uberfire.java.nio.file.FileSystemNotFoundException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with KProperty

use of org.uberfire.ext.metadata.model.KProperty in project kie-wb-common by kiegroup.

the class ResourceReference method toIndexElements.

@Override
public List<KProperty<?>> toIndexElements() {
    final List<KProperty<?>> indexElements = new ArrayList<>();
    // Impact Analysis references
    if (resourceFQN != null) {
        ValueReferenceIndexTerm refTerm = new ValueReferenceIndexTerm(this.resourceFQN, this.resourceType);
        indexElements.add(new KPropertyImpl<>(refTerm.getTerm(), refTerm.getValue()));
    }
    if (this.fieldNamepartReferenceMap != null) {
        fieldNamepartReferenceMap.values().forEach((refPartTerm) -> indexElements.add(new KPropertyImpl<>(refPartTerm.getTerm(), refPartTerm.getValue())));
    }
    return indexElements;
}
Also used : KProperty(org.uberfire.ext.metadata.model.KProperty) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) ArrayList(java.util.ArrayList)

Example 5 with KProperty

use of org.uberfire.ext.metadata.model.KProperty in project kie-wb-common by kiegroup.

the class GitKeepFileIndexerTest method testTheUsualBuild.

@Test
public void testTheUsualBuild() throws Exception {
    final KieModule kieModule = mock(KieModule.class);
    doReturn(kieModule).when(moduleService).resolveModule(any(Path.class));
    doReturn("Module Name").when(kieModule).getModuleName();
    doReturn(getPathMock("default://main@myRepository/Test")).when(kieModule).getRootPath();
    final Package aPackage = mock(Package.class);
    doReturn("pkgName").when(aPackage).getPackageName();
    doReturn(aPackage).when(moduleService).resolvePackage(any(Path.class));
    final IndexBuilder indexBuilder = indexer.fillIndexBuilder(mainPath);
    final Set<KProperty<?>> properties = indexBuilder.build();
    assertEquals(3, properties.size());
    assertTrue(properties.contains(new KPropertyImpl<>(ModuleRootPathIndexTerm.TERM, "default://main@myRepository/Test")));
    assertTrue(properties.contains(new KPropertyImpl<>(ModuleNameIndexTerm.TERM, "Module Name")));
    assertTrue(properties.contains(new KPropertyImpl<>(PackageNameIndexTerm.TERM, "pkgName")));
}
Also used : Path(org.uberfire.backend.vfs.Path) KPropertyImpl(org.kie.workbench.common.services.refactoring.KPropertyImpl) KProperty(org.uberfire.ext.metadata.model.KProperty) Package(org.guvnor.common.services.project.model.Package) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Aggregations

KProperty (org.uberfire.ext.metadata.model.KProperty)14 ArrayList (java.util.ArrayList)7 KObject (org.uberfire.ext.metadata.model.KObject)7 Test (org.junit.Test)6 HashSet (java.util.HashSet)4 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)3 Path (org.uberfire.java.nio.file.Path)3 List (java.util.List)2 ValuePartIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm)2 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)2 PageResponse (org.uberfire.paging.PageResponse)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1