Commit da44b81f authored by Matija Obreza's avatar Matija Obreza

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
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}+):(.+))?$");
public static enum AliasType {
......@@ -99,15 +101,19 @@ public class AccessionAlias extends BasicModel implements AccessionRelated, Self
public AccessionAlias(AliasType aliasType, String name) {
this.aliasType = aliasType;
Matcher m = USED_BY_PATTERN.matcher(name);
if (m.matches()) {
this.usedBy = StringUtils.trimToNull(m.group(2));
this.name = StringUtils.trimToNull(m.group(3));
} else {
if (name.startsWith(":")) {
name = StringUtils.trimToNull(name.substring(1));
if (name != null) {
Matcher m = USED_BY_PATTERN.matcher(name);
if (m.matches()) {
this.usedBy = StringUtils.trimToNull(m.group(2));
this.name = StringUtils.trimToNull(m.group(3));
} else {
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
}
public boolean isEmpty() {
return StringUtils.isBlank(name);
return StringUtils.isBlank(name) || ! HAS_WORD_CHARACTER.matcher(name).find();
}
@Override
......
......@@ -91,6 +91,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
/** acce.lists uuid */
public Set<UUID> list;
/** accession aliases */
public StringFilter alias;
/* (non-Javadoc)
* @see org.genesys.blocks.model.filters.BasicModelFilter#buildQuery()
......@@ -169,6 +172,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
if (CollectionUtil.isNotEmpty(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?
if (sgsv != null) {
and.and(accession.accessionId.duplSite.any().eq("NOR051"));
......
......@@ -235,6 +235,10 @@ public class AppliedFiltersConverter {
f.lastModifiedDate = convertDateFilter(af);
break;
}
case FilterConstants.ALIAS: {
f.alias = convertStringFilter(af);
break;
}
default:
throw new RuntimeException("Unhandled Accession filter property=" + filterName);
}
......
......@@ -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(
Collectors.toList());
if (!toRemove.isEmpty() || !toAdd.isEmpty()) {
LOG.info("Removing: {} Adding: {}", toRemove, toAdd);
LOG.trace("Removing: {} Adding: {}", toRemove, toAdd);
}
existing.removeAll(toRemove);
existing.addAll(toAdd);
......
......@@ -4340,12 +4340,22 @@ databaseChangeLog:
join taxonomy2 t2 on a.taxonomyId2 = t2.id;
- changeSet:
id: 1538732843596-5
author: vpavlov
comment: drop subset_accession
id: 1538732843596-5
author: vpavlov
comment: drop subset_accession
changes:
- 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
# - changeSet:
......
......@@ -16,6 +16,9 @@
package org.genesys.test.simpletest;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
......@@ -24,6 +27,8 @@ import java.util.Set;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
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;
public class NamesTest extends NoContextTest {
......@@ -92,4 +97,27 @@ public class NamesTest extends NoContextTest {
}
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