Skip to content
Snippets Groups Projects
Commit bf947c59 authored by Adam Laskowski's avatar Adam Laskowski
Browse files

BIS-1024: Moved pattern from property type to property assignment

parent 580887cf
No related branches found
No related tags found
No related merge requests found
Showing
with 99 additions and 144 deletions
......@@ -93,6 +93,12 @@ public class PropertyAssignment
@JsonProperty
private boolean managedInternally;
@JsonProperty
private String pattern;
@JsonProperty
private String patternType;
// Method automatically generated with DtoGenerator
@JsonIgnore
public PropertyAssignmentFetchOptions getFetchOptions()
......@@ -336,6 +342,28 @@ public class PropertyAssignment
this.managedInternally = managedInternally;
}
@JsonIgnore
public String getPattern()
{
return pattern;
}
public void setPattern(String pattern)
{
this.pattern = pattern;
}
@JsonIgnore
public String getPatternType()
{
return patternType;
}
public void setPatternType(String patternType)
{
this.patternType = patternType;
}
// Method automatically generated with DtoGenerator
@Override
public String toString()
......
......@@ -99,12 +99,6 @@ public class PropertyType implements Serializable, ICodeHolder, IDescriptionHold
@JsonProperty
private Boolean multiValue;
@JsonProperty
private String pattern;
@JsonProperty
private String patternType;
// Method automatically generated with DtoGenerator
@JsonIgnore
public PropertyTypeFetchOptions getFetchOptions()
......@@ -379,28 +373,6 @@ public class PropertyType implements Serializable, ICodeHolder, IDescriptionHold
this.multiValue = multiValue;
}
@JsonIgnore
public String getPattern()
{
return pattern;
}
public void setPattern(String pattern)
{
this.pattern = pattern;
}
@JsonIgnore
public String getPatternType()
{
return patternType;
}
public void setPatternType(String patternType)
{
this.patternType = patternType;
}
// Method automatically generated with DtoGenerator
@Override
public String toString()
......
......@@ -49,6 +49,10 @@ public class PropertyAssignmentCreation implements ICreation
private boolean managedInternally = false;
private String patternType;
private String pattern;
public String getSection()
{
return section;
......@@ -149,6 +153,26 @@ public class PropertyAssignmentCreation implements ICreation
this.managedInternally = managedInternally;
}
public String getPattern()
{
return pattern;
}
public void setPattern(String pattern)
{
this.pattern = pattern;
}
public String getPatternType()
{
return patternType;
}
public void setPatternType(String patternType)
{
this.patternType = patternType;
}
@Override
public String toString()
{
......
......@@ -72,12 +72,6 @@ public class PropertyTypeCreation implements ICreation, IObjectCreation
@JsonProperty
private Boolean multiValue;
@JsonProperty
private String pattern;
@JsonProperty
private String patternType;
@JsonIgnore
public String getCode()
{
......@@ -231,28 +225,6 @@ public class PropertyTypeCreation implements ICreation, IObjectCreation
this.multiValue = multiValue;
}
@JsonIgnore
public String getPattern()
{
return pattern;
}
public void setPattern(String pattern)
{
this.pattern = pattern;
}
@JsonIgnore
public String getPatternType()
{
return patternType;
}
public void setPatternType(String patternType)
{
this.patternType = patternType;
}
@Override
public String toString()
{
......
......@@ -59,12 +59,6 @@ public class PropertyTypeUpdate implements IUpdate, IObjectUpdate<IPropertyTypeI
@JsonProperty
private ListUpdateMapValues metaData = new ListUpdateMapValues();
@JsonProperty
private FieldUpdateValue<String> pattern = new FieldUpdateValue<String>();
@JsonProperty
private FieldUpdateValue<String> patternType = new FieldUpdateValue<String>();
@Override
@JsonIgnore
public IPropertyTypeId getObjectId()
......@@ -144,30 +138,6 @@ public class PropertyTypeUpdate implements IUpdate, IObjectUpdate<IPropertyTypeI
this.transformation.setValue(transformation);
}
@JsonIgnore
public FieldUpdateValue<String> getPattern()
{
return pattern;
}
@JsonIgnore
public void setPattern(String pattern)
{
this.pattern.setValue(pattern);
}
@JsonIgnore
public FieldUpdateValue<String> getPatternType()
{
return patternType;
}
@JsonIgnore
public void setPatternType(String patternType)
{
this.patternType.setValue(patternType);
}
@JsonIgnore
public ListUpdateMapValues getMetaData()
{
......
......@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javax.annotation.Resource;
......@@ -61,6 +62,9 @@ public class CreatePropertyAssignmentsExecutor
@Autowired
private IMapPluginByIdExecutor mapPluginByIdExecutor;
@Autowired
private IPatternCompiler patternCompiler;
public void createPropertyAssignments(final IOperationContext context, String entityTypeCode,
Collection<? extends PropertyAssignmentCreation> propertyAssignments, ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind entityKind)
......@@ -144,6 +148,16 @@ public class CreatePropertyAssignmentsExecutor
assignment.setShowRawValue(assignmentCreation.isShowRawValueInForms());
assignment.setUnique(assignmentCreation.isUnique());
assignment.setManagedInternally(assignmentCreation.isManagedInternally());
//if only one element out of pair (pattern, patternType) is empty, throw exception
if(((assignmentCreation.getPattern() == null || assignmentCreation.getPattern().trim().isEmpty()) && (assignmentCreation.getPatternType() != null && !assignmentCreation.getPatternType().trim().isEmpty()))
|| ((assignmentCreation.getPattern() != null && !assignmentCreation.getPattern().trim().isEmpty()) && (assignmentCreation.getPatternType() == null || assignmentCreation.getPatternType().trim().isEmpty())))
{
throw new UserFailureException("Pattern and Pattern Type must be both either empty or non-empty!");
}
assignment.setPatternType(assignmentCreation.getPatternType());
assignment.setPattern(assignmentCreation.getPattern());
Pattern pattern = patternCompiler.compilePattern(assignmentCreation.getPattern(), assignmentCreation.getPatternType());
assignment.setPatternRegex(pattern == null ? null : pattern.pattern());
return assignment;
}
......
......@@ -15,7 +15,7 @@
*
*/
package ch.ethz.sis.openbis.generic.server.asapi.v3.executor.property;
package ch.ethz.sis.openbis.generic.server.asapi.v3.executor.entity;
import java.util.regex.Pattern;
......
......@@ -15,7 +15,7 @@
*
*/
package ch.ethz.sis.openbis.generic.server.asapi.v3.executor.property;
package ch.ethz.sis.openbis.generic.server.asapi.v3.executor.entity;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import org.springframework.stereotype.Component;
......@@ -65,7 +65,8 @@ public final class PatternCompiler implements IPatternCompiler
private String prepareValue(String value)
{
String result = value.strip();
if(result.charAt(0) != '"' || result.charAt(result.length()-1) != '"')
if((result.charAt(0) != '"' && result.charAt(0) != '“')
|| (result.charAt(result.length()-1) != '"' && result.charAt(result.length()-1) != '”'))
{
throw new UserFailureException("Wrong value format: '" + value + "'");
}
......
......@@ -23,6 +23,7 @@ import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.entity.IPatternCompiler;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
......@@ -129,12 +130,6 @@ public class CreatePropertyTypeExecutor
{
throw new UserFailureException("Vocabulary id has been specified but data type is " + dataType + ".");
}
//if only one element out of pair (pattern, patternType) is empty, throw exception
if(((creation.getPattern() == null || creation.getPattern().trim().isEmpty()) && (creation.getPatternType() != null && !creation.getPatternType().trim().isEmpty()))
|| ((creation.getPattern() != null && !creation.getPattern().trim().isEmpty()) && (creation.getPatternType() == null || creation.getPatternType().trim().isEmpty())))
{
throw new UserFailureException("Pattern and Pattern Type must be both either empty or non-empty!");
}
validateMaterialType(creation, dataType);
validateSampleType(creation, dataType);
validateSchemaAndDataType(dataType.name(), creation.getSchema());
......@@ -219,10 +214,6 @@ public class CreatePropertyTypeExecutor
propertyType.setMetaData(creation.getMetaData());
propertyType.setMultiValue(
creation.isMultiValue() != null && creation.isMultiValue());
propertyType.setPattern(creation.getPattern());
propertyType.setPatternType(creation.getPatternType());
Pattern pattern = patternCompiler.compilePattern(creation.getPattern(), creation.getPatternType());
propertyType.setPatternRegex(pattern == null ? null : pattern.pattern());
propertyTypes.add(propertyType);
}
......
......@@ -23,7 +23,7 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE;
import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.entity.IPatternCompiler;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
......@@ -100,11 +100,6 @@ public class UpdatePropertyTypeExecutor
{
throw new UserFailureException("Description cannot be empty.");
}
if(update.getPattern().isModified() && update.getPatternType().isModified() && ((StringUtils.isEmpty(update.getPattern().getValue()) && !StringUtils.isEmpty(update.getPatternType().getValue()))
|| (!StringUtils.isEmpty(update.getPattern().getValue()) && StringUtils.isEmpty(update.getPatternType().getValue()))))
{
throw new UserFailureException("Pattern and Pattern Type must be both either empty or non-empty!");
}
}
@Override
......@@ -143,11 +138,6 @@ public class UpdatePropertyTypeExecutor
CreatePropertyTypeExecutor.validateTransformationAndDataType(dataType, update.getTransformation().getValue());
propertyType.setTransformation(getNewValue(update.getTransformation(), propertyType.getTransformation()));
updateMetaData(propertyType, update);
propertyType.setPattern(getNewValue(update.getPattern(), propertyType.getPattern()));
propertyType.setPatternType(getNewValue(update.getPatternType(), propertyType.getPatternType()));
Pattern updateRegex = patternCompiler.compilePattern(propertyType.getPattern(), propertyType.getPatternType());
propertyType.setPatternRegex(updateRegex == null ? null : updateRegex.pattern());
}
......
......@@ -55,6 +55,12 @@ public class PropertyAssignmentRecord extends ObjectBaseRecord
public Boolean is_unique;
public String pattern;
public String pattern_type;
public String pattern_regex;
// IS_MANAGED_INTERNALLY_NAMESPACE
public Boolean is_managed_internally_assignment;
}
......@@ -129,6 +129,8 @@ public class PropertyAssignmentTranslator implements IPropertyAssignmentTranslat
assignment.setRegistrationDate(assignmentRecord.registration_timestamp);
assignment.setUnique(assignmentRecord.is_unique);
assignment.setFetchOptions(assignmentFetchOptions);
assignment.setPattern(assignmentRecord.pattern);
assignment.setPatternType(assignmentRecord.pattern_type);
assignment.setManagedInternally(assignmentRecord.is_managed_internally_assignment);
PropertyAssignmentKey key = new PropertyAssignmentKey(assignmentRecord.id, entityKind);
......
......@@ -44,10 +44,4 @@ public class PropertyTypeRecord extends ObjectBaseRecord
public Boolean is_multi_value;
public String pattern;
public String pattern_type;
public String pattern_regex;
}
......@@ -127,8 +127,6 @@ public class PropertyTypeTranslator extends AbstractCachingTranslator<Long, Prop
result.setRegistrationDate(baseRecord.registration_timestamp);
result.setMetaData(CommonUtils.asMap(baseRecord.meta_data));
result.setMultiValue(baseRecord.is_multi_value);
result.setPattern(baseRecord.pattern);
result.setPatternType(baseRecord.pattern_type);
if (fetchOptions.hasVocabulary())
{
......
......@@ -190,8 +190,8 @@ public abstract class AbstractXLSEntityTypeExportHelper<ENTITY_TYPE extends IEnt
plugin != null ? (plugin.getName() != null ? plugin.getName() + ".py" : "") : "",
String.valueOf(propertyType.isMultiValue() != null && propertyType.isMultiValue()).toUpperCase(),
String.valueOf(propertyAssignment.isUnique() != null && propertyAssignment.isUnique()).toUpperCase(),
String.valueOf(propertyType.getPattern() != null ? propertyType.getPattern() : ""),
String.valueOf(propertyType.getPatternType() != null ? propertyType.getPatternType() : ""),
String.valueOf(propertyAssignment.getPattern() != null ? propertyAssignment.getPattern() : ""),
String.valueOf(propertyAssignment.getPatternType() != null ? propertyAssignment.getPatternType() : ""),
String.valueOf(propertyAssignment.isManagedInternally() != null && propertyAssignment.isManagedInternally()).toUpperCase()
};
addRow(rowNumber++, false, exportableKind, permId, warnings, valueFiles, values);
......
......@@ -154,6 +154,8 @@ public class PropertyAssignmentImportHelper extends BasicImportHelper
String section = getValueByColumnName(headers, values, Attribute.Section);
String script = getValueByColumnName(headers, values, Attribute.DynamicScript);
String unique = getValueByColumnName(headers, values, Attribute.Unique);
String pattern = getValueByColumnName(headers, values, Attribute.Pattern);
String patternType = getValueByColumnName(headers, values, Attribute.PatternType);
String internalAssignment = getValueByColumnName(headers, values, Attribute.InternalAssignment);
PropertyAssignmentCreation creation = new PropertyAssignmentCreation();
......@@ -163,6 +165,8 @@ public class PropertyAssignmentImportHelper extends BasicImportHelper
creation.setShowInEditView(Boolean.parseBoolean(showInEditViews));
creation.setSection(section);
creation.setUnique(Boolean.parseBoolean(unique));
creation.setPattern(pattern);
creation.setPatternType(patternType);
creation.setManagedInternally(Boolean.parseBoolean(internalAssignment));
if (script != null && !script.isEmpty())
......
......@@ -205,8 +205,6 @@ public class PropertyTypeImportHelper extends BasicImportHelper
String vocabularyCode = getValueByColumnName(header, values, Attribute.VocabularyCode);
String metadata = getValueByColumnName(header, values, Attribute.Metadata);
String multiValued = getValueByColumnName(header, values, Attribute.MultiValued);
String pattern = getValueByColumnName(header, values, Attribute.Pattern);
String patternType = getValueByColumnName(header, values, Attribute.PatternType);
PropertyTypeCreation creation = new PropertyTypeCreation();
creation.setCode(code);
......@@ -244,11 +242,6 @@ public class PropertyTypeImportHelper extends BasicImportHelper
creation.setMultiValue(false);
}
if(pattern != null && !pattern.isEmpty() && patternType != null && !patternType.isEmpty())
{
creation.setPattern(pattern);
creation.setPatternType(patternType);
}
delayedExecutor.createPropertyType(creation, page, line);
}
......@@ -263,8 +256,6 @@ public class PropertyTypeImportHelper extends BasicImportHelper
String dataType = getValueByColumnName(header, values, Attribute.DataType);
String vocabularyCode = getValueByColumnName(header, values, Attribute.VocabularyCode);
String metadata = getValueByColumnName(header, values, Attribute.Metadata);
String pattern = getValueByColumnName(header, values, Attribute.Pattern);
String patternType = getValueByColumnName(header, values, Attribute.PatternType);
PropertyTypePermId propertyTypePermId = new PropertyTypePermId(code);
......@@ -324,12 +315,6 @@ public class PropertyTypeImportHelper extends BasicImportHelper
update.getMetaData().add(JSONHandler.parseMetaData(metadata));
}
if(pattern != null && !pattern.isEmpty() && patternType != null && !patternType.isEmpty())
{
update.getPattern().setValue(pattern);
update.getPatternType().setValue(patternType);
}
delayedExecutor.updatePropertyType(update, page, line);
}
......
......@@ -138,7 +138,9 @@ public class EntityTypePropertyTypeBO extends AbstractBusinessObject implements
createAssignment(newAssignment.isMandatory(), newAssignment.getSection(),
newAssignment.getOrdinal(), entityType, propertyType, scriptOrNull,
newAssignment.isShownInEditView(), newAssignment.getShowRawValue(),
newAssignment.isUnique(), newAssignment.isManagedInternally());
newAssignment.isUnique(), newAssignment.isManagedInternally(),
newAssignment.getPatternType(), newAssignment.getPattern(),
newAssignment.getPatternRegex());
String defaultValue = newAssignment.getDefaultValue();
if (newAssignment.isDynamic())
{
......@@ -290,6 +292,10 @@ public class EntityTypePropertyTypeBO extends AbstractBusinessObject implements
assignment.setShownInEditView(assignmentUpdates.isShownInEditView());
assignment.setShowRawValue(assignmentUpdates.getShowRawValue());
assignment.setPattern(assignmentUpdates.getPattern());
assignment.setPatternType(assignmentUpdates.getPatternType());
assignment.setPatternRegex(assignmentUpdates.getPatternRegex());
UpdateAuthorizationSnapshot snapshotAfter = new UpdateAuthorizationSnapshot(assignment);
if (snapshotBefore.equals(snapshotAfter) == false)
......@@ -323,7 +329,8 @@ public class EntityTypePropertyTypeBO extends AbstractBusinessObject implements
private EntityTypePropertyTypePE createAssignment(final boolean mandatory,
final String section, final Long previousETPTOrdinal, final EntityTypePE entityType,
final PropertyTypePE propertyType, ScriptPE scriptOrNull, boolean shownInEditView,
boolean showRawValue, boolean unique, boolean isManagedInternally)
boolean showRawValue, boolean unique, boolean isManagedInternally, String patternType,
String pattern, String patternRegex)
{
checkAssignmentDoesNotExist(entityType, propertyType);
Long previousOrdinal =
......@@ -346,6 +353,9 @@ public class EntityTypePropertyTypeBO extends AbstractBusinessObject implements
etpt.setShowRawValue(showRawValue);
etpt.setUnique(unique);
etpt.setManagedInternallyNamespace(isManagedInternally);
etpt.setPatternType(patternType);
etpt.setPattern(pattern);
etpt.setPatternRegex(patternRegex);
new InternalPropertyTypeAuthorization().canCreatePropertyAssignment(session, etpt.getPropertyType(), etpt);
......
......@@ -87,11 +87,6 @@ public final class PropertyTypeBO extends VocabularyBO implements IPropertyTypeB
propertyTypePE.setRegistrator(findPerson());
propertyTypePE.setManagedInternally(propertyType.isManagedInternally());
propertyTypePE.setMultiValue(propertyType.isMultiValue());
propertyTypePE.setPattern(propertyType.getPattern());
propertyTypePE.setPatternType(propertyType.getPatternType());
propertyTypePE.setPatternRegex(propertyType.getPattern() != null
? "REGEX:" + propertyType.getPattern()
: null);
if (DataTypeCode.CONTROLLEDVOCABULARY.equals(dataTypePE.getCode()))
{
......
......@@ -37,8 +37,7 @@ public interface IPropertyListingQuery
* label are already HTML escaped.
*/
@Select(sql = "select pt.id as pt_id, pt.code as pt_code, dt.code as dt_code,"
+ " pt.label as pt_label, pt.is_managed_internally, pt.schema, pt.transformation,"
+ " pt.pattern, pt.pattern_type"
+ " pt.label as pt_label, pt.is_managed_internally, pt.schema, pt.transformation"
+ " from property_types pt join data_types dt on pt.daty_id=dt.id", resultSetBinding = PropertyTypeDataObjectBinding.class)
public PropertyType[] getPropertyTypes();
......
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