@Nullable @Override public String getIdFromToken(final String continuationToken) { try { return continuationToken != null ? entityAdapter.recordIdentity(new DetachedEntityId(continuationToken)).toString() : null; } catch (IllegalArgumentException e) { throw new ContinuationTokenException( format("Caught exception parsing id from continuation token '%s'", continuationToken), e); } }
@Override public Iterable<EntityId> browse(final CleanupPolicy policy, final Repository repository) { if (policy.getCriteria().isEmpty()) { return emptyList(); } QueryBuilder query = convertPolicyToQuery(policy); log.debug("Searching for components to cleanup using policy {}", policy); return transform(searchService.browseUnrestrictedInRepos(query, ImmutableList.of(repository.getName())), searchHit -> new DetachedEntityId(searchHit.getId())); }
/** * Returns detached entity metadata. */ public DetachedEntityMetadata detach() { return new DetachedEntityMetadata( new DetachedEntityId(id.getValue()), new DetachedEntityVersion(version.getValue()) ); }
@Override public List<Component> findMatchingComponents(final Repository repository, final String componentId, final String componentGroup, final String componentName, final String componentVersion) { if (null == repository || null == componentId || componentId.isEmpty()) { return emptyList(); } else { try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); Component component = storageTx.findComponent(new DetachedEntityId(componentId)); if (component != null) { return singletonList(component); } else { return emptyList(); } } } } }
private Component getComponent(final RepositoryItemIDXO repositoryItemIDXO, final Repository repository) { try { return ofNullable(browseService .getComponentById(componentEntityAdapter.recordIdentity(new DetachedEntityId(repositoryItemIDXO.getId())), repository)).orElseThrow( () -> new NotFoundException("Unable to locate component with id " + repositoryItemIDXO.getValue())); } catch (IllegalArgumentException e) { log.debug("IllegalArgumentException caught retrieving component with id {}", repositoryItemIDXO.getId(), e); throw new WebApplicationException(format("Unable to process component with id %s", repositoryItemIDXO.getId()), UNPROCESSABLE_ENTITY); } }
@Override public BrowseResult<Asset> browseComponentAssets(final Repository repository, final String componentId) { checkNotNull(repository); checkNotNull(componentId); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); Component component = storageTx.findComponent(new DetachedEntityId(componentId)); if (component == null) { return new BrowseResult<>(0, Collections.emptyList()); } return browseComponentAssetsHelper(storageTx, repository, component); } }
@GET @Path("/{id}") public AssetXO getAssetById(@PathParam("id") final String id) { RepositoryItemIDXO repositoryItemIDXO = fromString(id); Repository repository = repositoryManagerRESTAdapter.getRepository(repositoryItemIDXO.getRepositoryId()); Asset asset = getAsset(id, repository, new DetachedEntityId(repositoryItemIDXO.getId())); return fromAsset(asset, repository); }
@DELETE @Path("/{id}") public void deleteAsset(@PathParam("id") final String id) { RepositoryItemIDXO repositoryItemIDXO = fromString(id); Repository repository = repositoryManagerRESTAdapter.getRepository(repositoryItemIDXO.getRepositoryId()); DetachedEntityId entityId = new DetachedEntityId(repositoryItemIDXO.getId()); Asset asset = getAsset(id, repository, entityId); if (repository != null && asset != null) { maintenanceService.deleteAsset(repository, asset); } }
@Override public PagedResponse<Component> browseByPage(final CleanupPolicy policy, final Repository repository, final QueryOptions options) { checkNotNull(options.getStart()); checkNotNull(options.getLimit()); StorageTx tx = UnitOfWork.currentTx(); QueryBuilder query = convertPolicyToQuery(policy, options); log.debug("Searching for components to cleanup using policy {}", policy); SearchResponse searchResponse = searchService.searchUnrestrictedInRepos(query, getSort(options.getSortProperty(), options.getSortDirection()), options.getStart(), options.getLimit(), ImmutableList.of(repository.getName())); List<Component> components = stream(searchResponse.getHits().spliterator(), false) .map(searchHit -> tx.findComponent(new DetachedEntityId(searchHit.getId()))) .filter(Objects::nonNull) .collect(toList()); return new PagedResponse<>(searchResponse.getHits().getTotalHits(), components); }