Skip to content
Snippets Groups Projects
Commit 49a64df7 authored by buczekp's avatar buczekp
Browse files

[LMS-1979] allow to change text of displayed entity links and load sample's permId by code

SVN: 20275
parent b0b08da9
No related branches found
No related tags found
No related merge requests found
...@@ -19,12 +19,18 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.managed_property; ...@@ -19,12 +19,18 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.managed_property;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.shared.ResourceNames; import ch.systemsx.cisd.openbis.generic.shared.ResourceNames;
import ch.systemsx.cisd.openbis.generic.shared.basic.IIdentifierHolder; import ch.systemsx.cisd.openbis.generic.shared.basic.IIdentifierHolder;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory;
import ch.systemsx.cisd.openbis.generic.shared.managed_property.EntityLinkElementTranslator; import ch.systemsx.cisd.openbis.generic.shared.managed_property.EntityLinkElementTranslator;
import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IEntityInformationProvider; import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IEntityInformationProvider;
import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IEntityLinkElement; import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IEntityLinkElement;
...@@ -35,7 +41,6 @@ import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IEntityLinkE ...@@ -35,7 +41,6 @@ import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IEntityLinkE
@Component(value = ResourceNames.ENTITY_INFORMATION_PROVIDER) @Component(value = ResourceNames.ENTITY_INFORMATION_PROVIDER)
public class EntityInformationProvider implements IEntityInformationProvider public class EntityInformationProvider implements IEntityInformationProvider
{ {
// @Autowired
private final IDAOFactory daoFactory; private final IDAOFactory daoFactory;
@Autowired @Autowired
...@@ -45,6 +50,14 @@ public class EntityInformationProvider implements IEntityInformationProvider ...@@ -45,6 +50,14 @@ public class EntityInformationProvider implements IEntityInformationProvider
this.daoFactory = daoFactory; this.daoFactory = daoFactory;
} }
public String getIdentifier(IEntityLinkElement entityLink)
{
final EntityKind entityKind =
EntityLinkElementTranslator.translate(entityLink.getEntityLinkKind());
final String permId = entityLink.getPermId();
return getIdentifier(entityKind, permId);
}
private String getIdentifier(EntityKind entityKind, String permId) private String getIdentifier(EntityKind entityKind, String permId)
{ {
IIdentifierHolder identifierHolderOrNull = null; IIdentifierHolder identifierHolderOrNull = null;
...@@ -89,12 +102,36 @@ public class EntityInformationProvider implements IEntityInformationProvider ...@@ -89,12 +102,36 @@ public class EntityInformationProvider implements IEntityInformationProvider
return identifierHolderOrNull == null ? null : identifierHolderOrNull.getIdentifier(); return identifierHolderOrNull == null ? null : identifierHolderOrNull.getIdentifier();
} }
public String getIdentifier(IEntityLinkElement entityLink) public String getSamplePermId(String spaceCode, String sampleCode)
{ {
final EntityKind entityKind = DatabaseInstancePE homeInstance = daoFactory.getDatabaseInstanceDAO().getHomeInstance();
EntityLinkElementTranslator.translate(entityLink.getEntityLinkKind()); SpacePE space =
final String permId = entityLink.getPermId(); daoFactory.getSpaceDAO().tryFindSpaceByCodeAndDatabaseInstance(spaceCode,
return getIdentifier(entityKind, permId); homeInstance);
if (space == null)
{
throw new UserFailureException("space " + spaceCode + " doesn't exist");
}
SamplePE sample = daoFactory.getSampleDAO().tryFindByCodeAndSpace(sampleCode, space);
return (sample != null) ? sample.getPermId() : null;
}
public String getSamplePermId(String sampleIdentifier)
{
SampleIdentifier identifier = SampleIdentifierFactory.parse(sampleIdentifier);
String sampleCode = identifier.getSampleCode();
if (identifier.isSpaceLevel())
{
String spaceCode = identifier.getSpaceLevel().getSpaceCode();
return getSamplePermId(spaceCode, sampleCode);
} else
{
DatabaseInstancePE homeInstance = daoFactory.getDatabaseInstanceDAO().getHomeInstance();
SamplePE sample =
daoFactory.getSampleDAO().tryFindByCodeAndDatabaseInstance(sampleCode,
homeInstance);
return (sample != null) ? sample.getPermId() : null;
}
} }
} }
...@@ -111,18 +111,27 @@ public class SimpleTableModelBuilderAdaptor implements ISimpleTableModelBuilderA ...@@ -111,18 +111,27 @@ public class SimpleTableModelBuilderAdaptor implements ISimpleTableModelBuilderA
public void setCell(String headerTitle, IEntityLinkElement value) public void setCell(String headerTitle, IEntityLinkElement value)
{ {
row.setCell(headerTitle, asTableCell(value)); row.setCell(headerTitle, asTableCell(value, null));
} }
private EntityTableCell asTableCell(IEntityLinkElement value) public void setCell(String headerTitle, IEntityLinkElement value, String linkText)
{
row.setCell(headerTitle, asTableCell(value, linkText));
}
private EntityTableCell asTableCell(IEntityLinkElement value,
String linkTextOrNull)
{ {
final EntityKind entityKind = final EntityKind entityKind =
EntityLinkElementTranslator.translate(value.getEntityLinkKind()); EntityLinkElementTranslator.translate(value.getEntityLinkKind());
final String permId = value.getPermId(); final String permId = value.getPermId();
final String identifierOrNull = tryExtractIdentifier(value); final String identifierOrNull = tryExtractIdentifier(value);
return new EntityTableCell(entityKind, permId, identifierOrNull);
}
final EntityTableCell result =
new EntityTableCell(entityKind, permId, identifierOrNull);
result.setLinkText(linkTextOrNull);
return result;
}
}; };
} }
......
...@@ -31,4 +31,16 @@ public interface IEntityInformationProvider ...@@ -31,4 +31,16 @@ public interface IEntityInformationProvider
*/ */
String getIdentifier(IEntityLinkElement entityLink); String getIdentifier(IEntityLinkElement entityLink);
/**
* @return permId of entity specified by given space and sample, <code>null</code> if such an
* entity doesn't exist
*/
String getSamplePermId(String spaceCode, String sampleCode);
/**
* @return permId of entity specified by given identifier, <code>null</code> if such an entity
* doesn't exist
*/
String getSamplePermId(String sampleIdentifier);
} }
...@@ -30,28 +30,35 @@ public interface IRowBuilderAdaptor ...@@ -30,28 +30,35 @@ public interface IRowBuilderAdaptor
{ {
/** /**
* Sets the value of the column specified by the header title by the specified string. * Sets the value of the column specified by the header title to the specified string.
*/ */
public void setCell(String headerTitle, String value); public void setCell(String headerTitle, String value);
/** /**
* Sets the value of the column specified by the header title by the specified long value. * Sets the value of the column specified by the header title to the specified long value.
*/ */
public void setCell(String headerTitle, long value); public void setCell(String headerTitle, long value);
/** /**
* Sets the value of the column specified by the header title by the specified double value. * Sets the value of the column specified by the header title to the specified double value.
*/ */
public void setCell(String headerTitle, double value); public void setCell(String headerTitle, double value);
/** /**
* Sets the value of the column specified by the header title by the specified date. * Sets the value of the column specified by the header title to the specified date.
*/ */
public void setCell(String headerTitle, Date value); public void setCell(String headerTitle, Date value);
/** /**
* Sets the value of the column specified by the header title by the specified entity link. * Sets the value of the column specified by the header title to the specified entity link
* rendered using identifier.
*/ */
public void setCell(String headerTitle, IEntityLinkElement value); public void setCell(String headerTitle, IEntityLinkElement value);
/**
* Sets the value of the column specified by the header title to the specified entity link
* rendered using given text.
*/
public void setCell(String headerTitle, IEntityLinkElement value, String linkText);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment