Search in sources :

Example 16 with Artifact

use of se.light.assembly64.model.Artifact in project archiva by apache.

the class BrowseServiceTest method searchArtifacts.

@Test
public void searchArtifacts() throws Exception {
    // START SNIPPET: search-artifacts
    BrowseService browseService = getBrowseService(authorizationHeader, true);
    List<Artifact> artifactDownloadInfos = browseService.searchArtifacts("The Apache Software Foundation", TEST_REPO_ID, true);
    assertThat(artifactDownloadInfos).isNotNull().isNotEmpty().hasSize(7);
// END SNIPPET: search-artifacts
}
Also used : BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 17 with Artifact

use of se.light.assembly64.model.Artifact in project archiva by apache.

the class AbstractRestService method buildArtifacts.

protected List<Artifact> buildArtifacts(Collection<ArtifactMetadata> artifactMetadatas, String repositoryId) throws ArchivaRestServiceException {
    try {
        if (artifactMetadatas != null && !artifactMetadatas.isEmpty()) {
            List<Artifact> artifacts = new ArrayList<>(artifactMetadatas.size());
            for (ArtifactMetadata artifact : artifactMetadatas) {
                String repoId = repositoryId != null ? repositoryId : artifact.getRepositoryId();
                if (repoId == null) {
                    throw new IllegalStateException("Repository Id is null");
                }
                ManagedRepository repo = repositoryRegistry.getManagedRepository(repoId);
                if (repo == null) {
                    throw new RepositoryException("Repository not found " + repoId);
                }
                ManagedRepositoryContent content = repo.getContent();
                ArtifactBuilder builder = new ArtifactBuilder().forArtifactMetadata(artifact).withManagedRepositoryContent(content);
                Artifact art = builder.build();
                art.setUrl(getArtifactUrl(art, repositoryId));
                artifacts.add(art);
            }
            return artifacts;
        }
        return Collections.emptyList();
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArrayList(java.util.ArrayList) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryException(org.apache.archiva.repository.RepositoryException) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ArtifactBuilder(org.apache.archiva.rest.services.utils.ArtifactBuilder) Artifact(org.apache.archiva.maven2.model.Artifact)

Example 18 with Artifact

use of se.light.assembly64.model.Artifact in project archiva by apache.

the class DownloadMergedIndexNonDefaultPathTest method downloadMergedIndexWithNonDefaultPath.

@Test
public void downloadMergedIndexWithNonDefaultPath() throws Exception {
    Path indexBaseDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("archiva").resolve("remotedownloadtest");
    String indexBase = indexBaseDir.toString();
    FileUtils.deleteQuietly(indexBaseDir);
    if (!Files.exists(indexBaseDir)) {
        Files.createDirectories(indexBaseDir);
    }
    String id = Long.toString(System.currentTimeMillis());
    ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
    managedRepository.setIndexDirectory(indexBase + "/index-" + id);
    managedRepository.setPackedIndexDirectory(indexBase + "/indexPacked-" + id);
    ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    RepositoriesService repositoriesService = getRepositoriesService();
    repositoriesService.scanRepositoryNow(id, true);
    // wait a bit to ensure index is finished
    int timeout = 20000;
    while (timeout > 0 && repositoriesService.alreadyScanning(id)) {
        Thread.sleep(500);
        timeout -= 500;
    }
    RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
    String repoGroupId = "test-group";
    if (repositoryGroupService.getRepositoryGroup(repoGroupId) != null) {
        repositoryGroupService.deleteRepositoryGroup(repoGroupId);
    }
    RepositoryGroup repositoryGroup = new RepositoryGroup();
    repositoryGroup.setId(repoGroupId);
    String path = ".fooooo";
    repositoryGroup.setRepositories(Arrays.asList(id));
    repositoryGroup.setMergedIndexPath(path);
    repositoryGroupService.addRepositoryGroup(repositoryGroup);
    // create a repo with a remote on the one with index
    id = Long.toString(System.currentTimeMillis());
    managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
    managedRepository.setIndexDirectory(indexBaseDir + "/index-" + id);
    managedRepository.setPackedIndexDirectory(indexBase + "/tmpIndexPacked-" + id);
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    String remoteId = Long.toString(System.currentTimeMillis());
    RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
    remoteRepository.setId(remoteId);
    remoteRepository.setName(remoteId);
    remoteRepository.setDownloadRemoteIndex(true);
    remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
    remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/" + path);
    remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
    remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
    getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
    ProxyConnectorService proxyConnectorService = getProxyConnectorService();
    ProxyConnector proxyConnector = new ProxyConnector();
    proxyConnector.setProxyId("foo-bar2");
    proxyConnector.setSourceRepoId(id);
    proxyConnector.setTargetRepoId(remoteId);
    proxyConnectorService.addProxyConnector(proxyConnector);
    repositoriesService.scheduleDownloadRemoteIndex(remoteId, true, true);
    // wait the end
    while (!repositoriesService.getRunningRemoteDownloadIds().getStrings().isEmpty()) {
        Thread.sleep(500);
        log.debug("still running remote download");
    }
    SearchService searchService = getSearchService();
    SearchRequest request = new SearchRequest();
    request.setRepositories(Arrays.asList(id));
    request.setGroupId("org.apache.felix");
    List<Artifact> artifacts = searchService.searchArtifacts(request);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}
Also used : Path(java.nio.file.Path) SearchRequest(org.apache.archiva.rest.api.model.SearchRequest) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ProxyConnectorService(org.apache.archiva.rest.api.services.ProxyConnectorService) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Artifact(org.apache.archiva.maven2.model.Artifact) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) SearchService(org.apache.archiva.rest.api.services.SearchService) RepositoryGroupService(org.apache.archiva.rest.api.services.RepositoryGroupService) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) Test(org.junit.Test)

Example 19 with Artifact

use of se.light.assembly64.model.Artifact in project assembly64fx by freabemania.

the class SearchController method init.

public void init(Artifact searchEntry) throws Exception {
    localDb = LocalDBService.getInstance();
    userService = UserService.getInstance();
    searchService = SearchService.getInstance();
    mappingService = CategoryMappingService.getInstance();
    // populate years
    table.setPlaceholder(new Label(""));
    yearInput.getItems().add(ALL);
    IntStream.range(1980, Calendar.getInstance().get(Calendar.YEAR) + 1).forEach(item -> yearInput.getItems().add(String.valueOf(item)));
    yearInput.getSelectionModel().selectFirst();
    // populate ratings
    ratingInput.getItems().add(ALL);
    IntStream.range(1, 10).forEach(item -> ratingInput.getItems().add(String.valueOf(item)));
    ratingInput.getSelectionModel().selectFirst();
    categoryInput.getItems().add(ALL);
    List<CategoryMapping> l = new ArrayList<CategoryMapping>(mappingService.values());
    Collections.sort(l, (i1, i2) -> i1.getDescription().toLowerCase().compareTo(i2.getDescription().toLowerCase()));
    l.stream().forEach(item -> categoryInput.getItems().add(item.getDescription()));
    if (searchEntry != null) {
        try {
            CategoryMapping categoryMappingByName = mappingService.getCategoryMappingByName(searchEntry.getDatabaseId());
            categoryInput.getSelectionModel().select(categoryMappingByName.getDescription());
        } catch (Exception e) {
            categoryInput.getSelectionModel().selectFirst();
        }
    } else {
        categoryInput.getSelectionModel().selectFirst();
    }
    name.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("name"));
    group.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("group"));
    year.setCellValueFactory(new PropertyValueFactory<SearchResultItem, Integer>("year"));
    handle.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("handle"));
    event.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("event"));
    group.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("group"));
    rating.setCellValueFactory(new PropertyValueFactory<SearchResultItem, Integer>("rating"));
    category.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("categoryName"));
    updated.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("updated"));
    EventHandler<MouseEvent> mouseEventHandle = (MouseEvent event) -> {
        handleMouseClicked(event);
    };
    table.setOnKeyTyped(event -> {
        if (event.getCharacter().length() > 0 && event.getCharacter().charAt(0) == ENTER_KEY) {
            openFiles();
        }
    });
    table.addEventHandler(MouseEvent.MOUSE_PRESSED, mouseEventHandle);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    registerSearchOnEnter(nameInput);
    registerSearchOnEnter(groupInput);
    registerSearchOnEnter(handleInput);
    registerSearchOnEnter(eventInput);
    registerChoice(yearInput);
    registerChoice(categoryInput);
    registerChoice(ratingInput);
    checkCheckbox(t64, T64SEARCH);
    checkCheckbox(d64, D64SEARCH);
    checkCheckbox(d71, T71SEARCH);
    checkCheckbox(d81, T81SEARCH);
    checkCheckbox(prg, PRGSEARCH);
    checkCheckbox(tap, TAPSEARCH);
    checkCheckbox(crt, CRTSEARCH);
    checkCheckbox(bin, BINSEARCH);
    checkCheckbox(sid, SIDSEARCH);
    checkCheckbox(g64, G64SEARCH);
    searchPeriod.setItems(FXCollections.observableArrayList(SEARCH_PERIOD.ALL, SEARCH_PERIOD.ONE_DAY, SEARCH_PERIOD.TWO_DAYS, SEARCH_PERIOD.FOUR_DAYS, SEARCH_PERIOD.ONE_WEEK, SEARCH_PERIOD.TWO_WEEKS, SEARCH_PERIOD.THREE_WEEKS, SEARCH_PERIOD.ONE_MONTH, SEARCH_PERIOD.TWO_MONTHS));
    searchPeriod.getSelectionModel().select(0);
    try {
        searchPeriod.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends SEARCH_PERIOD> observable, SEARCH_PERIOD oldValue, SEARCH_PERIOD newValue) -> performSearch());
    } catch (Exception e) {
        logger.error("Unable to install listener", e);
    }
    registerCheckboxChangeForSearch(t64, T64SEARCH);
    registerCheckboxChangeForSearch(d64, D64SEARCH);
    registerCheckboxChangeForSearch(d71, T71SEARCH);
    registerCheckboxChangeForSearch(d81, T81SEARCH);
    registerCheckboxChangeForSearch(prg, PRGSEARCH);
    registerCheckboxChangeForSearch(tap, TAPSEARCH);
    registerCheckboxChangeForSearch(crt, CRTSEARCH);
    registerCheckboxChangeForSearch(bin, BINSEARCH);
    registerCheckboxChangeForSearch(sid, SIDSEARCH);
    registerCheckboxChangeForSearch(g64, G64SEARCH);
    searchFromStartOfString.selectedProperty().addListener(new ChangeListener<Boolean>() {

        public void changed(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
            ExecutorUtil.executeAsyncWithRetry(() -> {
                localDb.addLocalDBSetting("search_from_start", String.valueOf(newVal));
                return null;
            });
        }
    });
    String val = localDb.getLocalDBSetting("search_from_start");
    if (val != null) {
        searchFromStartOfString.setSelected(Boolean.valueOf(val));
    } else {
        searchFromStartOfString.setSelected(true);
    }
    if (!userService.isLocationSelectedAndExisting()) {
        downloadFolderImage.setVisible(false);
    }
}
Also used : SEARCH_PERIOD(se.light.assembly64.Support.SEARCH_PERIOD) CategoryMapping(se.light.assembly64.model.CategoryMapping) MouseEvent(javafx.scene.input.MouseEvent) Label(javafx.scene.control.Label) ArrayList(java.util.ArrayList) SearchResultItem(se.light.assembly64.model.SearchResultItem) ObservableValue(javafx.beans.value.ObservableValue) SearchException(se.light.assembly64.model.SearchException)

Example 20 with Artifact

use of se.light.assembly64.model.Artifact in project assembly64fx by freabemania.

the class InstallationService method unpackDynamic.

private void unpackDynamic(File content, LocationAndInstallationStatus location, Artifact entry, ArtifactDelta delta) throws Exception {
    CancelableTask cancelTask = CancelableTask.of();
    LocalStorageUtil.createDir(pathService.getTmpDynFolder());
    unzipService.extractZip(content, pathService.getTmpDynFolder(), entry);
    if (cancelTask.isCancelled()) {
        return;
    }
    File[] files = LocalStorageUtil.getSubdirOrFile(pathService.getTmpDynFolder(), entry.getFolder()).listFiles();
    File base = LocalStorageUtil.getSubdirOrFile(location.getLocation(), entry.getPrefix() + "/" + entry.getFolder());
    Optional<File> releaseLogFile = Arrays.stream(files).filter(item -> item.getName().equals("releaselog.json")).findFirst();
    List<ReleaseInfo> releaseInfoList = null;
    List<ReleaseInfo> matchedReleaseInfoList = new ArrayList<>();
    if (releaseLogFile.isPresent()) {
        releaseInfoList = Support.readList(ReleaseInfo.class, releaseLogFile.get()).stream().collect(Collectors.toList());
        for (ReleaseInfo item : releaseInfoList) {
            String p = item.getPath();
            int start = p.indexOf("/", p.indexOf("/") + 1);
            item.setPath(entry.getPrefix() + "/" + entry.getFolder() + "/" + p.substring(start + 1));
            item.setStrippedPath(entry.getFolder() + "/" + p.substring(start + 1));
        }
    }
    for (File f : files) {
        if (f.isDirectory()) {
            String dirname = f.getName().toUpperCase();
            char firstChar = dirname.charAt(0);
            boolean isDigit = Character.isDigit(firstChar);
            boolean isAlpha = Character.isAlphabetic(firstChar);
            String target = findDestination(firstChar, dirname, base);
            if (target != null) {
                File t = null;
                if (isDigit) {
                    t = new File(base.getAbsolutePath() + "/0-9/" + target + "/" + f.getName());
                } else if (isAlpha) {
                    t = new File(base.getAbsolutePath() + "/" + String.valueOf(firstChar) + "/" + target + "/" + f.getName());
                } else {
                    t = new File(base.getAbsolutePath() + "/___MISC___/" + target + "/" + f.getName());
                }
                FileUtils.forceMkdir(t);
                FileUtils.copyDirectory(f, t);
                if (releaseInfoList != null) {
                    ReleaseInfo matchedReleaseInfo = null;
                    for (ReleaseInfo item : releaseInfoList) {
                        File[] subdirs = f.listFiles(File::isDirectory);
                        for (File dir : subdirs) {
                            if (dir.getPath().contains(item.getStrippedPath())) {
                                matchedReleaseInfo = item;
                                break;
                            }
                        }
                    }
                    if (matchedReleaseInfo != null) {
                        matchedReleaseInfo.setPath(t.getAbsolutePath().substring(base.getAbsolutePath().length() + 1));
                        matchedReleaseInfoList.add(matchedReleaseInfo);
                    }
                }
                ProgressControlWrapper.getInstance().setProgressLabel("Moved " + f.getName() + " to " + t.getAbsolutePath());
                if (cancelTask.isCancelled()) {
                    break;
                }
            } else {
                LOGGER.info("Unable to install " + dirname);
            }
        }
    }
    ProgressControlWrapper.getInstance().increaseProgress();
    if (releaseLogFile.isPresent()) {
        File t = new File(base.getAbsolutePath() + "/releaselog.json");
        LOGGER.info("Flushing rebuildt releaselog.json to " + t.getAbsolutePath());
        Support.flush(matchedReleaseInfoList, t);
    }
}
Also used : ArtifactDelta(se.light.assembly64.model.ArtifactDelta) ReturningTask(se.light.assembly64.model.ReturningTask) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Support.isRemoteArtifact(se.light.assembly64.Support.isRemoteArtifact) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) Support.getVersionAsInteger(se.light.assembly64.Support.getVersionAsInteger) ArtifactType(se.light.assembly64.model.ArtifactType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressDBController(se.light.assembly64.fx.ProgressDBController) GuiUtils(se.light.assembly64.util.GuiUtils) Map(java.util.Map) Support(se.light.assembly64.Support) Support.flush(se.light.assembly64.Support.flush) CancelableTask(se.light.assembly64.model.CancelableTask) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) Support.getObjectMapper(se.light.assembly64.Support.getObjectMapper) ContentEntry(se.light.assembly64.model.ContentEntry) GenericMessageDialogController(se.light.assembly64.fx.GenericMessageDialogController) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Artifact(se.light.assembly64.model.Artifact) Collectors(java.util.stream.Collectors) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) File(java.io.File) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) Platform(javafx.application.Platform) ProgressControlWrapper(se.light.assembly64.fx.ProgressControlWrapper) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) SearchResultItem(se.light.assembly64.model.SearchResultItem) NullWindowOwner(se.light.assembly64.fx.NullWindowOwner) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) DOWNLOAD_STATUS(se.light.assembly64.service.FTPService.DOWNLOAD_STATUS) ProgressMessageBox(se.light.assembly64.ProgressMessageBox) FILE_ACTION(se.light.assembly64.Support.FILE_ACTION) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) ArrayList(java.util.ArrayList) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) File(java.io.File) CancelableTask(se.light.assembly64.model.CancelableTask)

Aggregations

Artifact (org.apache.archiva.maven2.model.Artifact)37 Test (org.junit.Test)29 SearchService (org.apache.archiva.rest.api.services.SearchService)14 ArrayList (java.util.ArrayList)13 BrowseService (org.apache.archiva.rest.api.services.BrowseService)11 File (java.io.File)10 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)9 Artifact (se.light.assembly64.model.Artifact)9 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)8 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)8 Path (java.nio.file.Path)7 List (java.util.List)6 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)6 CancelableTask (se.light.assembly64.model.CancelableTask)6 IOException (java.io.IOException)5 Optional (java.util.Optional)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ArtifactDelta (se.light.assembly64.model.ArtifactDelta)5 ArtifactType (se.light.assembly64.model.ArtifactType)5