Skip to content

Commit

Permalink
Merge pull request #1036 from olgabozhko/bugfix/266-form-list-ref-use…
Browse files Browse the repository at this point in the history
…-always-flag-disabled

 #266 Исправлено ложное срабатывание проверки
  • Loading branch information
vadimeg authored Jun 15, 2022
2 parents 9a30199 + 58c5bf8 commit dea9703
Show file tree
Hide file tree
Showing 11 changed files with 1,127 additions and 55 deletions.
1 change: 1 addition & 0 deletions bundles/com.e1c.v8codestyle.form/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Import-Package: com._1c.g5.v8.bm.core;version="[7.5.0,8.0.0)",
com._1c.g5.v8.dt.form.model;version="[10.0.0,11.0.0)",
com._1c.g5.v8.dt.form.service.datasourceinfo;version="[3.0.0,4.0.0)",
com._1c.g5.v8.dt.mcore;version="[6.0.0,7.0.0)",
com._1c.g5.v8.dt.metadata.dbview;version="4.0.0",
com._1c.g5.v8.dt.metadata.mdclass;version="[8.0.0,9.0.0)",
com._1c.g5.wiring;version="[2.2.0,3.0.0)",
com._1c.g5.wiring.binder;version="[1.1.0,2.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com._1c.g5.v8.dt.form.model.AbstractDataPath;
import com._1c.g5.v8.dt.form.model.DynamicListExtInfo;
import com._1c.g5.v8.dt.form.model.FormAttribute;
import com._1c.g5.v8.dt.metadata.dbview.DbViewFieldDef;
import com._1c.g5.v8.dt.metadata.dbview.DbViewTableDef;
import com.e1c.g5.v8.dt.check.CheckComplexity;
import com.e1c.g5.v8.dt.check.ICheckParameters;
import com.e1c.g5.v8.dt.check.components.BasicCheck;
Expand All @@ -43,8 +45,22 @@ public class FormListRefUseAlwaysFlagDisabledCheck
{

private static final String CHECK_ID = "form-list-ref-use-always-flag-disabled"; //$NON-NLS-1$
private static final List<String> REF_ABSTRACT_DATA_PATH = List.of("List", "Ref"); //$NON-NLS-1$ //$NON-NLS-2$
private static final List<String> REF_ABSTRACT_DATA_PATH_RU = List.of("Список", "Ссылка"); //$NON-NLS-1$ //$NON-NLS-2$
private static final List<String> REF_ABSTRACT_DATA_PATH = List.of("Ref", "Список"); //$NON-NLS-1$ //$NON-NLS-2$

private static final Predicate<? super DbViewFieldDef> NAME_CHECK =
name -> name.getName().equals(REF_ABSTRACT_DATA_PATH.get(0));

private static Predicate<AbstractDataPath> pathCheck = path -> {
EList<String> segments = path.getSegments();

if (segments.size() != 2)
{
return false;
}

return segments.get(1).equals(REF_ABSTRACT_DATA_PATH.get(0))
|| segments.get(1).equals(REF_ABSTRACT_DATA_PATH.get(1));
};

@Override
public String getCheckId()
Expand All @@ -58,7 +74,7 @@ protected void configureCheck(CheckConfigurer builder)
builder.title(Messages.FormListRefUseAlwaysFlagDisabledCheck_title)
.description(Messages.FormListRefUseAlwaysFlagDisabledCheck_description)
.complexity(CheckComplexity.NORMAL)
.severity(IssueSeverity.MAJOR)
.severity(IssueSeverity.MINOR)
.issueType(IssueType.UI_STYLE)
.extension(new StandardCheckExtension(getCheckId(), CorePlugin.PLUGIN_ID))
.topObject(FORM)
Expand All @@ -70,41 +86,17 @@ protected void configureCheck(CheckConfigurer builder)
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
{

if (monitor.isCanceled() || !(object instanceof FormAttribute))
{
return;
}

FormAttribute formAttribute = (FormAttribute)object;
if (formAttribute.getExtInfo() instanceof DynamicListExtInfo
&& formAttribute.getNotDefaultUseAlwaysAttributes().stream().noneMatch(pathCheck))
if (formAttribute.getExtInfo() instanceof DynamicListExtInfo)
{
resultAceptor.addIssue(
Messages.FormListRefUseAlwaysFlagDisabledCheck_UseAlways_flag_is_disabled_for_the_Ref_field,
formAttribute);
DbViewTableDef tableDef = (DbViewTableDef)((DynamicListExtInfo)formAttribute.getExtInfo()).getMainTable();
if (tableDef != null && tableDef.getFields().stream().anyMatch(NAME_CHECK)
&& formAttribute.getNotDefaultUseAlwaysAttributes().stream().noneMatch(pathCheck))
{
resultAceptor.addIssue(
Messages.FormListRefUseAlwaysFlagDisabledCheck_UseAlways_flag_is_disabled_for_the_Ref_field,
FORM_ATTRIBUTE__NOT_DEFAULT_USE_ALWAYS_ATTRIBUTES);
}
}

}

private Predicate<AbstractDataPath> pathCheck = path -> {
EList<String> segments = path.getSegments();
if (segments.size() != 2)
{
return false;
}

if (!segments.get(0).equals(REF_ABSTRACT_DATA_PATH.get(0))
&& !segments.get(0).equals(REF_ABSTRACT_DATA_PATH_RU.get(0)))
{
return false;
}
if (!segments.get(1).equals(REF_ABSTRACT_DATA_PATH.get(1))
&& !segments.get(1).equals(REF_ABSTRACT_DATA_PATH_RU.get(1)))
{
return false;
}
return true;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*******************************************************************************/
package com.e1c.v8codestyle.form.check.itests;

import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
Expand All @@ -30,8 +31,6 @@
import com._1c.g5.v8.dt.form.model.Form;
import com._1c.g5.v8.dt.form.model.FormItem;
import com._1c.g5.v8.dt.form.model.Table;
import com._1c.g5.v8.dt.metadata.mdclass.Configuration;
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
import com._1c.g5.v8.dt.validation.marker.Marker;
import com.e1c.g5.v8.dt.testing.check.CheckTestBase;
import com.e1c.v8codestyle.form.check.FormListRefUseAlwaysFlagDisabledCheck;
Expand All @@ -46,11 +45,13 @@ public class FormListRefUseAlwaysFlagDisabledCheckTest
{
private static final String CHECK_ID = "form-list-ref-use-always-flag-disabled";
private static final String PROJECT_NAME = "FormListRefUseAlwaysFlagDisabled";
private static final String FQN_FORM = "Catalog.TestCatalog.Form.TestListForm.Form";
private static final String FQN_FORM_EN = "Catalog.TestCatalog.Form.TestListForm.Form";
private static final String FQN_FORM_RU = "Catalog.TestCatalog.Form.TestListFormRu.Form";
private static final String FQN_NON_OBJECT = "InformationRegister.TestInformationRegister.Form.TestListForm.Form";


/**
* Test Use Always flag is disabled for the Reference attribute in dynamic list (En Script variant).
* Test Use Always flag is disabled for the Reference attribute in dynamic list (En variant).
*
* @throws Exception the exception
*/
Expand All @@ -60,15 +61,18 @@ public void testUseAlwaysDisabledForRef() throws Exception
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
assertNotNull(dtProject);

IBmObject object = getTopObjectByFqn(FQN_FORM, dtProject);
IBmObject object = getTopObjectByFqn(FQN_FORM_EN, dtProject);
assertTrue(object instanceof Form);

Form form = (Form)object;
assertTrue(form.getAttributes().get(0).getNotDefaultUseAlwaysAttributes().isEmpty());

Marker marker = getFirstNestedMarker(CHECK_ID, object.bmGetId(), dtProject);
assertNotNull(marker);
}

/**
* Test Use Always flag is enabled for the Reference attribute in dynamic list (En Script variant).
* Test Use Always flag is enabled for the Reference attribute in dynamic list (En variant).
*
* @throws Exception the exception
*/
Expand All @@ -84,25 +88,27 @@ public void testUseAlwaysEnabledForRef() throws Exception
@Override
public Void execute(IBmTransaction transaction, IProgressMonitor monitor)
{
Form form = (Form)transaction.getTopObjectByFqn(FQN_FORM);
Form form = (Form)transaction.getTopObjectByFqn(FQN_FORM_EN);
FormItem item = form.getItems().get(1);
assertTrue(item instanceof Table);
Table table = (Table)item;
AbstractDataPath path = (DataPath)table.getItems().get(0).eContents().get(1);
form.getAttributes().get(0).getNotDefaultUseAlwaysAttributes().add(path);
assertFalse(form.getAttributes().get(0).getNotDefaultUseAlwaysAttributes().isEmpty());
return null;
}
});
waitForDD(dtProject);

IBmObject object = getTopObjectByFqn(FQN_FORM, dtProject);
IBmObject object = getTopObjectByFqn(FQN_FORM_EN, dtProject);
assertTrue(object instanceof Form);

Marker marker = getFirstNestedMarker(CHECK_ID, object.bmGetId(), dtProject);
assertNull(marker);
}

/**
* Test Use Always flag is disabled for the Reference attribute in dynamic list (Ru script variant).
* Test Use Always flag is disabled for the Reference attribute in dynamic list (Ru variant).
*
* @throws Exception the exception
*/
Expand All @@ -112,23 +118,105 @@ public void testUseAlwaysDisabledForRefRu() throws Exception
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
assertNotNull(dtProject);

IBmObject object = getTopObjectByFqn(FQN_FORM_RU, dtProject);
assertTrue(object instanceof Form);

Form form = (Form)object;
assertTrue(form.getAttributes().get(0).getNotDefaultUseAlwaysAttributes().isEmpty());

Marker marker = getFirstNestedMarker(CHECK_ID, object.bmGetId(), dtProject);
assertNotNull(marker);
}

/**
* Test Use Always flag is enabled for the Reference attribute in dynamic list (Ru variant).
*
* @throws Exception the exception
*/
@Test
public void testUseAlwaysEnabledForRefRu() throws Exception
{
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
assertNotNull(dtProject);

IBmModel model = bmModelManager.getModel(dtProject);
model.execute(new AbstractBmTask<Void>("change mode")
{
@Override
public Void execute(IBmTransaction transaction, IProgressMonitor monitor)
{
Form form = (Form)transaction.getTopObjectByFqn(FQN_FORM_RU);
FormItem item = form.getItems().get(1);
assertTrue(item instanceof Table);
Table table = (Table)item;
AbstractDataPath path = (DataPath)table.getItems().get(0).eContents().get(1);
form.getAttributes().get(0).getNotDefaultUseAlwaysAttributes().add(path);
assertFalse(form.getAttributes().get(0).getNotDefaultUseAlwaysAttributes().isEmpty());
return null;
}
});
waitForDD(dtProject);

IBmObject object = getTopObjectByFqn(FQN_FORM_RU, dtProject);
assertTrue(object instanceof Form);

Marker marker = getFirstNestedMarker(CHECK_ID, object.bmGetId(), dtProject);
assertNull(marker);
}

/**
* Test Use Always flag is disabled for an attribute in dynamic list of the non object table.
*
* @throws Exception the exception
*/
@Test
public void testUseAlwaysDisabledForAttributeOnNonObjectTable() throws Exception
{
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
assertNotNull(dtProject);

IBmObject object = getTopObjectByFqn(FQN_NON_OBJECT, dtProject);
assertTrue(object instanceof Form);

Form form = (Form)object;
assertTrue(form.getAttributes().get(0).getNotDefaultUseAlwaysAttributes().isEmpty());

Marker marker = getFirstNestedMarker(CHECK_ID, object.bmGetId(), dtProject);
assertNull(marker);
}

/**
* Test Use Always flag is enabled in the dynamic list for an attribute with a nonstandard data path.
*
* @throws Exception the exception
*/
@Test
public void testUseAlwaysEnabledForAttributeWithNonStandardDataPath() throws Exception
{
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
assertNotNull(dtProject);

IBmModel model = bmModelManager.getModel(dtProject);
model.execute(new AbstractBmTask<Void>("change mode")
{
@Override
public Void execute(IBmTransaction transaction, IProgressMonitor monitor)
{
IBmObject object = transaction.getTopObjectByFqn(CONFIGURATION.getName());
assertTrue(object instanceof Configuration);
Configuration config = (Configuration)object;
config.setScriptVariant(ScriptVariant.RUSSIAN);
assertTrue(config.getScriptVariant() == ScriptVariant.RUSSIAN);
Form form = (Form)transaction.getTopObjectByFqn(FQN_FORM_EN);
FormItem item = form.getItems().get(1);
assertTrue(item instanceof Table);
Table table = (Table)item;
AbstractDataPath path = (DataPath)table.getItems().get(0).eContents().get(1);
path.getSegments().add(0, "SomeExtraSegment");
form.getAttributes().get(0).getNotDefaultUseAlwaysAttributes().add(path);
assertEquals("/SomeExtraSegment/List/Ref",
form.getAttributes().get(0).getNotDefaultUseAlwaysAttributes().get(0).toString());
return null;
}
});
waitForDD(dtProject);

IBmObject object = getTopObjectByFqn(FQN_FORM, dtProject);
IBmObject object = getTopObjectByFqn(FQN_FORM_EN, dtProject);
assertTrue(object instanceof Form);

Marker marker = getFirstNestedMarker(CHECK_ID, object.bmGetId(), dtProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
<id>16</id>
<visible>true</visible>
<enabled>true</enabled>
<userVisible>
<common>true</common>
</userVisible>
<userVisible/>
<dataPath xsi:type="form:DataPath">
<segments>List.Ref</segments>
</dataPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Settings xmlns="http://v8.1c.ru/8.1/data-composition-system/settings" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:v8="http://v8.1c.ru/8.1/data/core" xmlns:v8ui="http://v8.1c.ru/8.1/data/ui" xmlns:style="http://v8.1c.ru/8.1/data/ui/style" xmlns:sys="http://v8.1c.ru/8.1/data/ui/fonts/system" xmlns:web="http://v8.1c.ru/8.1/data/ui/colors/web" xmlns:win="http://v8.1c.ru/8.1/data/ui/colors/windows" xmlns:dcscor="http://v8.1c.ru/8.1/data-composition-system/core">
<filter>
<viewMode>Normal</viewMode>
<userSettingID>aedbafd4-ee68-4b02-b464-c89d9e5fb5b3</userSettingID>
</filter>
<order>
<viewMode>Normal</viewMode>
<userSettingID>88643ec8-04ad-448a-9f47-a8428df49498</userSettingID>
</order>
<conditionalAppearance>
<viewMode>Normal</viewMode>
<userSettingID>4fdb9617-54d0-44cb-929a-ed78fbc204cb</userSettingID>
</conditionalAppearance>
<itemsViewMode>Normal</itemsViewMode>
<itemsUserSettingID>6059f7fa-59c7-4902-83c5-d0df8017afec</itemsUserSettingID>
</Settings>
Loading

0 comments on commit dea9703

Please sign in to comment.