Skip to content

Добавлено чтение информации о типе формы (обычная или управляемая) #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* This file is a part of MDClasses.
*
* Copyright © 2019 - 2021
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* MDClasses is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* MDClasses is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with MDClasses.
*/
package com.github._1c_syntax.mdclasses.mdo;

import com.github._1c_syntax.mdclasses.mdo.children.form.FormData;
import com.github._1c_syntax.mdclasses.mdo.support.FormType;
import com.github._1c_syntax.mdclasses.unmarshal.wrapper.DesignerMDO;
import com.github._1c_syntax.mdclasses.utils.MDOFactory;
import com.github._1c_syntax.mdclasses.utils.MDOPathUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.nio.file.Path;

/**
* Базовый класс объектов форм
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true, onlyExplicitlyIncluded = true)
@NoArgsConstructor
public abstract class AbstractMDOForm extends AbstractMDObjectBSL {

/**
* Тип формы
*/
private FormType formType = FormType.MANAGED;

/**
* Данные формы. Читается из отдельного файла
* и предоставляет информацию о:
* + список элементов формы
* + список обработчиков формы
* + список реквизитов формы
*/
private FormData data;

/**
* Путь к файлу с данными формы
*/
private Path formDataPath;

protected AbstractMDOForm(DesignerMDO designerMDO) {
super(designerMDO);
formType = designerMDO.getProperties().getFormType();
}

@Override
public void supplement() {
super.supplement();
computeFormData();
}

@Override
public void supplement(AbstractMDObjectBase parent) {
super.supplement(parent);
computeFormData();
}

private void computeFormData() {
formDataPath = MDOPathUtils.getFormDataPath(this);
MDOFactory.readFormData(formDataPath).ifPresent(this::setData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@
*/
package com.github._1c_syntax.mdclasses.mdo;

import com.github._1c_syntax.mdclasses.mdo.children.form.FormData;
import com.github._1c_syntax.mdclasses.mdo.metadata.Metadata;
import com.github._1c_syntax.mdclasses.mdo.support.MDOType;
import com.github._1c_syntax.mdclasses.unmarshal.wrapper.DesignerMDO;
import com.github._1c_syntax.mdclasses.utils.MDOFactory;
import com.github._1c_syntax.mdclasses.utils.MDOPathUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.nio.file.Path;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true, onlyExplicitlyIncluded = true)
Expand All @@ -45,29 +40,9 @@
groupName = "CommonForms",
groupNameRu = "ОбщиеФормы"
)
public class MDCommonForm extends AbstractMDObjectBSL implements MDOForm {
/**
* Данные формы. Читается из отдельного файла
* и предоставляет информацию о:
* + список элементов формы
* + список обработчиков формы
* + список реквизитов формы
*/
private FormData data;

/**
* Путь к файлу с данными формы
*/
private Path formDataPath;

public class MDCommonForm extends AbstractMDOForm {
public MDCommonForm(DesignerMDO designerMDO) {
super(designerMDO);
}

@Override
public void supplement() {
super.supplement();
formDataPath = MDOPathUtils.getFormDataPath(this);
MDOFactory.readFormData(formDataPath).ifPresent(this::setData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,15 @@
*/
package com.github._1c_syntax.mdclasses.mdo.children;

import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBSL;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
import com.github._1c_syntax.mdclasses.mdo.MDOForm;
import com.github._1c_syntax.mdclasses.mdo.children.form.FormData;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDOForm;
import com.github._1c_syntax.mdclasses.mdo.metadata.Metadata;
import com.github._1c_syntax.mdclasses.mdo.support.MDOType;
import com.github._1c_syntax.mdclasses.unmarshal.wrapper.DesignerMDO;
import com.github._1c_syntax.mdclasses.utils.MDOFactory;
import com.github._1c_syntax.mdclasses.utils.MDOPathUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.nio.file.Path;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true, onlyExplicitlyIncluded = true)
Expand All @@ -48,29 +41,9 @@
groupName = "Forms",
groupNameRu = "Формы"
)
public class Form extends AbstractMDObjectBSL implements MDOForm {
/**
* Данные формы. Читается из отдельного файла
* и предоставляет информацию о:
* + список элементов формы
* + список обработчиков формы
* + список реквизитов формы
*/
private FormData data;

/**
* Путь к файлу с данными формы
*/
private Path formDataPath;
public class Form extends AbstractMDOForm {

public Form(DesignerMDO designerMDO) {
super(designerMDO);
}

@Override
public void supplement(AbstractMDObjectBase parent) {
super.supplement(parent);
formDataPath = MDOPathUtils.getFormDataPath(this);
MDOFactory.readFormData(formDataPath).ifPresent(this::setData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,23 @@
* You should have received a copy of the GNU Lesser General Public
* License along with MDClasses.
*/
package com.github._1c_syntax.mdclasses.mdo;
package com.github._1c_syntax.mdclasses.mdo.support;

import com.github._1c_syntax.mdclasses.mdo.children.form.FormData;
/**
* Тип формы (обычная или управляемая)
*/
public enum FormType implements EnumWithValue {
ORDINARY("Ordinary"),
MANAGED("Managed");

private final String value;

public interface MDOForm {
FormData getData();
FormType(String value) {
this.value = value;
}

void setData(FormData formData);
@Override
public String value() {
return this.value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.github._1c_syntax.mdclasses.mdo.support.ConfigurationExtensionPurpose;
import com.github._1c_syntax.mdclasses.mdo.support.DataLockControlMode;
import com.github._1c_syntax.mdclasses.mdo.support.DataPath;
import com.github._1c_syntax.mdclasses.mdo.support.FormType;
import com.github._1c_syntax.mdclasses.mdo.support.MDOModule;
import com.github._1c_syntax.mdclasses.mdo.support.MDOType;
import com.github._1c_syntax.mdclasses.mdo.support.MessageDirection;
Expand Down Expand Up @@ -352,6 +353,7 @@ private void registerConverters(XStream xStream) {
xStream.registerConverter(new EnumConverter<>(ObjectBelonging.class));
xStream.registerConverter(new EnumConverter<>(TemplateType.class));
xStream.registerConverter(new EnumConverter<>(DataLockControlMode.class));
xStream.registerConverter(new EnumConverter<>(FormType.class));
xStream.registerConverter(new AttributeConverter());
xStream.registerConverter(new CompatibilityModeConverter());
xStream.registerConverter(new PairConverter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.github._1c_syntax.mdclasses.mdo.children.template.TemplateType;
import com.github._1c_syntax.mdclasses.mdo.support.ConfigurationExtensionPurpose;
import com.github._1c_syntax.mdclasses.mdo.support.DataLockControlMode;
import com.github._1c_syntax.mdclasses.mdo.support.FormType;
import com.github._1c_syntax.mdclasses.mdo.support.MessageDirection;
import com.github._1c_syntax.mdclasses.mdo.support.ObjectBelonging;
import com.github._1c_syntax.mdclasses.mdo.support.ReturnValueReuse;
Expand Down Expand Up @@ -133,5 +134,7 @@ public class DesignerProperties {

@XStreamAlias("TemplateType")
private TemplateType templateType = TemplateType.SPREADSHEET_DOCUMENT;
@XStreamAlias("FormType")
private FormType formType = FormType.ORDINARY;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.github._1c_syntax.mdclasses.mdo.attributes.TabularSection;
import com.github._1c_syntax.mdclasses.mdo.metadata.AttributeType;
import com.github._1c_syntax.mdclasses.mdo.support.FormType;
import com.github._1c_syntax.mdclasses.mdo.support.MDOType;
import com.github._1c_syntax.mdclasses.mdo.support.ModuleType;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -61,7 +62,8 @@ void testDesigner() {
var mdo = getMDObjectDesigner("Catalogs/Справочник1.xml");
checkBaseField(mdo, MDCatalog.class, "Справочник1",
"eeef463d-d5e7-42f2-ae53-10279661f59d");
checkForms(mdo, 3, "Catalog.Справочник1", "ФормаЭлемента", "ФормаСписка", "ФормаВыбора");
checkForms(mdo, 4, "Catalog.Справочник1", "ФормаЭлемента", "ФормаСписка", "ФормаВыбора",
"ФормаЭлементаОбычная");
checkTemplates(mdo, 2, "Catalog.Справочник1", "Макет", "Макет2");
checkCommands(mdo, 1, "Catalog.Справочник1", "Команда1");
checkAttributes(((AbstractMDObjectComplex) mdo).getAttributes(), 4, "Catalog.Справочник1",
Expand All @@ -72,6 +74,10 @@ void testDesigner() {
checkAttributes(tabularSection.getAttributes(), 2,
"Catalog.Справочник1.TabularSection.ТабличнаяЧасть1", AttributeType.ATTRIBUTE);
assertThat(((AbstractMDObjectBSL) mdo).getModules()).isEmpty();

var catalog = (MDCatalog) mdo;
assertThat(catalog.getForms())
.anyMatch(form -> form.getFormType() == FormType.ORDINARY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
*/
package com.github._1c_syntax.mdclasses.mdo;

import com.github._1c_syntax.mdclasses.mdo.support.FormType;
import com.github._1c_syntax.mdclasses.mdo.support.MDOType;
import com.github._1c_syntax.mdclasses.mdo.support.ModuleType;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class MDCommonFormTest extends AbstractMDOTest {
MDCommonFormTest() {
super(MDOType.COMMON_FORM);
Expand All @@ -36,6 +39,7 @@ void testEDT() {
var mdo = getMDObjectEDT("CommonForms/Форма/Форма.mdo");
checkBaseField(mdo, MDCommonForm.class, "Форма",
"5ac59104-28a5-40b1-ab5b-2857fb41991a");
assertThat(((AbstractMDOForm) mdo).getFormType()).isEqualTo(FormType.MANAGED);
checkNoChildren(mdo);
checkModules(((AbstractMDObjectBSL) mdo).getModules(), 1,
"CommonForms/Форма", ModuleType.FormModule);
Expand All @@ -47,6 +51,7 @@ void testDesigner() {
var mdo = getMDObjectDesigner("CommonForms/Форма.xml");
checkBaseField(mdo, MDCommonForm.class, "Форма",
"5ac59104-28a5-40b1-ab5b-2857fb41991a");
assertThat(((AbstractMDOForm) mdo).getFormType()).isEqualTo(FormType.MANAGED);
checkNoChildren(mdo);
checkModules(((AbstractMDObjectBSL) mdo).getModules(), 1,
"CommonForms/Форма", ModuleType.FormModule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
import com.github._1c_syntax.mdclasses.ConfigurationExtension;
import com.github._1c_syntax.mdclasses.common.CompatibilityMode;
import com.github._1c_syntax.mdclasses.common.ConfigurationSource;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDOForm;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
import com.github._1c_syntax.mdclasses.mdo.MDCommonForm;
import com.github._1c_syntax.mdclasses.mdo.MDOForm;
import com.github._1c_syntax.mdclasses.mdo.children.Form;
import com.github._1c_syntax.mdclasses.mdo.support.ApplicationRunMode;
import com.github._1c_syntax.mdclasses.mdo.support.ConfigurationExtensionPurpose;
import com.github._1c_syntax.mdclasses.mdo.support.DataLockControlMode;
import com.github._1c_syntax.mdclasses.mdo.support.FormType;
import com.github._1c_syntax.mdclasses.mdo.support.MDOType;
import com.github._1c_syntax.mdclasses.mdo.support.ModuleType;
import com.github._1c_syntax.mdclasses.mdo.support.ObjectBelonging;
Expand Down Expand Up @@ -314,17 +315,17 @@ void testDesigner() {
assertThat(configuration.isUseManagedFormInOrdinaryApplication()).isTrue();
assertThat(configuration.isUseOrdinaryFormInManagedApplication()).isFalse();

assertThat(configuration.getModulesByType()).hasSize(17);
assertThat(configuration.getModulesByType()).hasSize(18);
assertThat(configuration.getModulesBySupport()).isEmpty();
assertThat(configuration.getModulesByObject()).hasSize(17);
assertThat(configuration.getModules()).hasSize(17);
assertThat(configuration.getModulesByObject()).hasSize(18);
assertThat(configuration.getModules()).hasSize(18);
assertThat(configuration.getCommonModules()).hasSize(6);
assertThat(configuration.getLanguages()).hasSize(3);

assertThat(configuration.getChildren()).hasSize(110);
assertThat(configuration.getChildren()).hasSize(111);
checkChildCount(configuration, MDOType.CONFIGURATION, 1);
checkChildCount(configuration, MDOType.COMMAND, 1);
checkChildCount(configuration, MDOType.FORM, 7);
checkChildCount(configuration, MDOType.FORM, 8);
checkChildCount(configuration, MDOType.TEMPLATE, 2);
checkChildCount(configuration, MDOType.ATTRIBUTE, 33);
checkChildCount(configuration, MDOType.WS_OPERATION, 2);
Expand Down Expand Up @@ -376,7 +377,7 @@ void testDesigner() {
checkChildCount(configuration, MDOType.WS_REFERENCE, 1);
checkChildCount(configuration, MDOType.XDTO_PACKAGE, 1);

assertThat(configuration.getChildrenByMdoRef()).hasSize(110);
assertThat(configuration.getChildrenByMdoRef()).hasSize(111);

assertThat(configuration.getCommonModule("ГлобальныйОбщийМодуль")).isPresent();
assertThat(configuration.getCommonModule("ГлобальныйОбщийМодуль3")).isNotPresent();
Expand Down Expand Up @@ -604,7 +605,9 @@ private void checkFillPath(Set<AbstractMDObjectBase> child) {
private void checkFormData(Set<AbstractMDObjectBase> child) {
var elements = child.parallelStream()
.filter(mdObjectBase -> mdObjectBase instanceof Form || mdObjectBase instanceof MDCommonForm)
.filter(mdObjectBase -> ((MDOForm) mdObjectBase).getData() == null)
.filter(mdObjectBase -> ((AbstractMDOForm) mdObjectBase).getFormType() == FormType.MANAGED)
.filter(mdObjectBase -> ((AbstractMDOForm) mdObjectBase).getData() == null)
.filter(mdObjectBase -> ((AbstractMDOForm) mdObjectBase).getData() == null)
.collect(Collectors.toList());
assertThat(elements).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
</ChildObjects>
</TabularSection>
<Form>ФормаЭлемента</Form>
<Form>ФормаЭлементаОбычная</Form>
<Form>ФормаСписка</Form>
<Form>ФормаВыбора</Form>
<Template>Макет</Template>
Expand All @@ -305,4 +306,4 @@
</Command>
</ChildObjects>
</Catalog>
</MetaDataObject>
</MetaDataObject>
Loading