Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: PLEASE DO NOT MERGE. #201

Merged
merged 9 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import gsrs.events.AbstractEntityUpdatedEvent;
import gsrs.repository.ControlledVocabularyRepository;
import gsrs.service.AbstractGsrsEntityService;
import ix.core.util.EntityUtils.Key;
import ix.ginas.models.v1.ControlledVocabulary;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
Expand All @@ -22,6 +24,8 @@
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@Scope(proxyMode = ScopedProxyMode.INTERFACES)
@Service
public class ControlledVocabularyEntityServiceImpl extends AbstractGsrsEntityService<ControlledVocabulary, Long> implements ControlledVocabularyEntityService {
Expand Down Expand Up @@ -154,6 +158,11 @@ protected Optional<Long> flexLookupIdOnly(String someKindOfId) {
return Optional.empty();
}

@Override
public List<Long> getIDs() {
return repository.getAllIDs();
}


// private SearchResult<ControlledVocabulary> parseQueryIntoMatch(String query, SearchSession session) {
// Pattern pattern = Pattern.compile("(\\S+):(\\S+)");
Expand Down Expand Up @@ -247,6 +256,11 @@ protected Optional<Long> flexLookupIdOnly(String someKindOfId) {

// }


@Override
public List<Key> getKeys() {
List<Long> IDs = repository.getAllIds();
List<Key> keys = IDs.stream().map(id->Key.ofStringId(ControlledVocabulary.class, Long.toString(id))).collect(Collectors.toList());
return keys;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;
@Repository
public interface ControlledVocabularyRepository extends GsrsVersionedRepository<ControlledVocabulary, Long> {

Expand All @@ -17,6 +18,9 @@ public interface ControlledVocabularyRepository extends GsrsVersionedRepository<
List<ControlledVocabulary> findByDomain(String domain);
@Query(value = "select * from ControlledVocabulary where id=:id", nativeQuery = true)
List<ControlledVocabulary> foo(String id);

@Query("select cv.id from ControlledVocabulary cv")
List<Long> getAllIds();

/**
* Summary of a ControlledVocabulary with only a few fields.
Expand All @@ -26,4 +30,8 @@ interface ControlledVocabularySummary {

String getDomain();
}

@Query("select cv.id from ControlledVocabulary cv")
List<Long> getAllIDs();

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ public class ReindexEntityEvent implements ReindexEvent {

private UUID reindexId;
private EntityUtils.Key entityKey;
private boolean requiresDelete=false;
private boolean requiresDelete = false;
private boolean excludeExternal = false;
private Optional<EntityWrapper<?>> optionalEntityWrapper = Optional.empty();


public ReindexEntityEvent(UUID reindexId, EntityUtils.Key entityKey, Optional<EntityWrapper<?>> of, boolean b) {
public ReindexEntityEvent(UUID reindexId, EntityUtils.Key entityKey, Optional<EntityWrapper<?>> of, boolean requiresDelete, boolean excludeExternal) {
this.reindexId=reindexId;
this.entityKey=entityKey;
this.optionalEntityWrapper=of;
this.requiresDelete=b;
this.requiresDelete=requiresDelete;
this.excludeExternal=excludeExternal;
}

public ReindexEntityEvent(UUID reindexId, EntityUtils.Key entityKey, Optional<EntityWrapper<?>> of, boolean b) {
this(reindexId,entityKey,of,b,false);
}
public ReindexEntityEvent(UUID reindexId, EntityUtils.Key entityKey, Optional<EntityWrapper<?>> of) {
this(reindexId,entityKey,of,false);
this(reindexId,entityKey,of,false,false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ public void updateEntity(Object obj) {
}

public void reindexEntity(Object obj, boolean deleteFirst) {
reindexEntity(obj, deleteFirst, false);
}

public void reindexEntity(Object obj, boolean deleteFirst, boolean excludeExternal) {
autowireIfNeeded();
EntityUtils.EntityWrapper ew = EntityUtils.EntityWrapper.of(obj);
if(ew.shouldIndex()) {
IndexerEventFactory indexerFactoryFor = indexerEventFactoryFactory.getIndexerFactoryFor(obj);
if(indexerFactoryFor !=null) {
// log.error("ew before publishing event :" + ew.toString());
applicationEventPublisher.publishEvent(indexerFactoryFor.newReindexEventFor(ew,deleteFirst));
applicationEventPublisher.publishEvent(indexerFactoryFor.newReindexEventFor(ew,deleteFirst,excludeExternal));

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ default Object newReindexEventFor(EntityUtils.EntityWrapper ew, boolean deleteFi
return new ReindexEntityEvent(UUID.randomUUID(), ew.getKey() ,Optional.of(ew),deleteFirst);
}

default Object newReindexEventFor(EntityUtils.EntityWrapper ew, boolean deleteFirst, boolean excludeExternal){
return new ReindexEntityEvent(UUID.randomUUID(), ew.getKey() ,Optional.of(ew),deleteFirst,excludeExternal);
}

/**
* Create a new UpdateIndexEvent object for the given wrapped Entity.
* The returned Object will be published to the {@link org.springframework.context.ApplicationEventPublisher}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.UUID;
import java.util.stream.Collectors;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import ix.core.models.Edit;
Expand All @@ -23,6 +24,9 @@ public interface EditRepository extends GsrsRepository<Edit, UUID> {

List<Edit> findByRefidAndVersion(String refId, String version);

@Query("select e.id from Edit e")
List<UUID> getAllIDs();

default Optional<Edit> findFirstByRefidOrderByCreatedDescAndKinds(String refId, Set<String> kinds){
return findByRefidOrderByCreatedDesc(refId)
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

import ix.core.models.Namespace;
import ix.core.models.Principal;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface NamespaceRepository extends GsrsRepository<Namespace, Long> {
Namespace findByName(String name);

@Query("select ns.id from Namespace ns")
List<Long> getAllIDs();
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void incrementReindexEvent(IncrementReindexEvent event){
public static void indexOneItem(UUID reindexId, Consumer<Object> eventConsumer, EntityUtils.Key key,
EntityUtils.EntityWrapper<ImportMetadata> wrappedEntity) {
log.trace("indexOneItem will process reindex of key {}", key);
ReindexEntityEvent event = new ReindexEntityEvent(reindexId, key, Optional.of(wrappedEntity), true);
ReindexEntityEvent event = new ReindexEntityEvent(reindexId, key, Optional.of(wrappedEntity), false);
eventConsumer.accept(event);
log.trace("submitted index event");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.function.BiFunction;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -400,6 +401,16 @@ public long getCount(){
return getEntityService().count();
}

@Override
@GetGsrsRestApiMapping("/@keys")
public List<Key> getKeys(){
List<I> IDs = getEntityService().getIDs();
// System.out.println("GET IDS!");
// IDs.forEach(id -> System.out.println("ID " + id.toString()));
List<Key> keys = IDs.stream().map(id->Key.ofStringId(getEntityService().getEntityClass(), id.toString())).collect(Collectors.toList());
return keys;
}

@Override
@GetGsrsRestApiMapping("")
@Transactional(readOnly = true)
Expand Down
Loading