Commit da44b81f authored by Matija Obreza's avatar Matija Obreza
Browse files

Added AccessionFilter#alias support

- alias name must contain at least one word character (number or letter)
parent b4cb5c55
...@@ -45,6 +45,8 @@ public class AccessionAlias extends BasicModel implements AccessionRelated, Self ...@@ -45,6 +45,8 @@ public class AccessionAlias extends BasicModel implements AccessionRelated, Self
private static final long serialVersionUID = 4990299133164025782L; private static final long serialVersionUID = 4990299133164025782L;
private static final Pattern HAS_WORD_CHARACTER = Pattern.compile("\\w", Pattern.MULTILINE);
private static Pattern USED_BY_PATTERN = Pattern.compile("^((\\p{Alnum}+):(.+))?$"); private static Pattern USED_BY_PATTERN = Pattern.compile("^((\\p{Alnum}+):(.+))?$");
public static enum AliasType { public static enum AliasType {
...@@ -99,15 +101,19 @@ public class AccessionAlias extends BasicModel implements AccessionRelated, Self ...@@ -99,15 +101,19 @@ public class AccessionAlias extends BasicModel implements AccessionRelated, Self
public AccessionAlias(AliasType aliasType, String name) { public AccessionAlias(AliasType aliasType, String name) {
this.aliasType = aliasType; this.aliasType = aliasType;
Matcher m = USED_BY_PATTERN.matcher(name); if (name != null) {
if (m.matches()) { Matcher m = USED_BY_PATTERN.matcher(name);
this.usedBy = StringUtils.trimToNull(m.group(2)); if (m.matches()) {
this.name = StringUtils.trimToNull(m.group(3)); this.usedBy = StringUtils.trimToNull(m.group(2));
} else { this.name = StringUtils.trimToNull(m.group(3));
if (name.startsWith(":")) { } else {
name = StringUtils.trimToNull(name.substring(1)); if (name.startsWith(":")) {
name = StringUtils.trimToNull(name.substring(1));
}
this.name = name;
} }
this.name = name; } else {
this.name = null;
} }
} }
...@@ -167,7 +173,7 @@ public class AccessionAlias extends BasicModel implements AccessionRelated, Self ...@@ -167,7 +173,7 @@ public class AccessionAlias extends BasicModel implements AccessionRelated, Self
} }
public boolean isEmpty() { public boolean isEmpty() {
return StringUtils.isBlank(name); return StringUtils.isBlank(name) || ! HAS_WORD_CHARACTER.matcher(name).find();
} }
@Override @Override
......
...@@ -91,6 +91,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> ...@@ -91,6 +91,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
/** acce.lists uuid */ /** acce.lists uuid */
public Set<UUID> list; public Set<UUID> list;
/** accession aliases */
public StringFilter alias;
/* (non-Javadoc) /* (non-Javadoc)
* @see org.genesys.blocks.model.filters.BasicModelFilter#buildQuery() * @see org.genesys.blocks.model.filters.BasicModelFilter#buildQuery()
...@@ -169,6 +172,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> ...@@ -169,6 +172,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
if (CollectionUtil.isNotEmpty(uuid)) { if (CollectionUtil.isNotEmpty(uuid)) {
and.and(accession.accessionId.uuid.in(uuid)); and.and(accession.accessionId.uuid.in(uuid));
} }
if (alias != null) {
and.and(alias.buildQuery(accession.accessionId.aliases.any().name));
}
// TODO Do we have to change this? // TODO Do we have to change this?
if (sgsv != null) { if (sgsv != null) {
and.and(accession.accessionId.duplSite.any().eq("NOR051")); and.and(accession.accessionId.duplSite.any().eq("NOR051"));
......
...@@ -235,6 +235,10 @@ public class AppliedFiltersConverter { ...@@ -235,6 +235,10 @@ public class AppliedFiltersConverter {
f.lastModifiedDate = convertDateFilter(af); f.lastModifiedDate = convertDateFilter(af);
break; break;
} }
case FilterConstants.ALIAS: {
f.alias = convertStringFilter(af);
break;
}
default: default:
throw new RuntimeException("Unhandled Accession filter property=" + filterName); throw new RuntimeException("Unhandled Accession filter property=" + filterName);
} }
......
...@@ -409,7 +409,7 @@ public class AccessionUploader implements InitializingBean { ...@@ -409,7 +409,7 @@ public class AccessionUploader implements InitializingBean {
List<AccessionRemark> toRemove = existing.stream().filter(ex -> ex == null || ex.isEmpty() || remarks.stream().filter(rem -> ex.equalTo(rem)).count() == 0).collect( List<AccessionRemark> toRemove = existing.stream().filter(ex -> ex == null || ex.isEmpty() || remarks.stream().filter(rem -> ex.equalTo(rem)).count() == 0).collect(
Collectors.toList()); Collectors.toList());
if (!toRemove.isEmpty() || !toAdd.isEmpty()) { if (!toRemove.isEmpty() || !toAdd.isEmpty()) {
LOG.info("Removing: {} Adding: {}", toRemove, toAdd); LOG.trace("Removing: {} Adding: {}", toRemove, toAdd);
} }
existing.removeAll(toRemove); existing.removeAll(toRemove);
existing.addAll(toAdd); existing.addAll(toAdd);
......
...@@ -4340,12 +4340,22 @@ databaseChangeLog: ...@@ -4340,12 +4340,22 @@ databaseChangeLog:
join taxonomy2 t2 on a.taxonomyId2 = t2.id; join taxonomy2 t2 on a.taxonomyId2 = t2.id;
- changeSet: - changeSet:
id: 1538732843596-5 id: 1538732843596-5
author: vpavlov author: vpavlov
comment: drop subset_accession comment: drop subset_accession
changes: changes:
- dropTable: - dropTable:
tableName: subset_accession tableName: subset_accession
- changeSet:
id: 1539510451000-1
author: mobreza
comment: Add index on accession_alias#name
changes:
- sql:
sql: >-
CREATE INDEX UK_cus8xep8hi5fv42o3ivu0name ON accession_alias(name(250))
# ENABLE AFTER SOME TIME # ENABLE AFTER SOME TIME
# - changeSet: # - changeSet:
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
package org.genesys.test.simpletest; package org.genesys.test.simpletest;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -24,6 +27,8 @@ import java.util.Set; ...@@ -24,6 +27,8 @@ import java.util.Set;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.genesys.test.base.NoContextTest; import org.genesys.test.base.NoContextTest;
import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
import org.junit.Test; import org.junit.Test;
public class NamesTest extends NoContextTest { public class NamesTest extends NoContextTest {
...@@ -92,4 +97,27 @@ public class NamesTest extends NoContextTest { ...@@ -92,4 +97,27 @@ public class NamesTest extends NoContextTest {
} }
return score; return score;
} }
@Test
public void testAliasIsBlank() {
assertThat(new AccessionAlias(AliasType.ACCENAME, "").isEmpty(), is(true));
assertThat(new AccessionAlias(AliasType.OTHERNUMB, "-").isEmpty(), is(true));
assertThat(new AccessionAlias(AliasType.ACCENAME, null).isEmpty(), is(true));
assertThat(new AccessionAlias(AliasType.ACCENAME, "a").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "0").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "Z").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "a0").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "0d").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "Z1").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "aa-").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "00-").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "ZZ-").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "aa-1").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "00-2").isEmpty(), is(false));
assertThat(new AccessionAlias(AliasType.ACCENAME, "ZZ-3").isEmpty(), is(false));
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment