|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (C) 2025, 1C-Soft LLC and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made |
| 5 | + * available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * 1C-Soft LLC - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | +package com.e1c.v8codestyle.md.role.check; |
| 14 | + |
| 15 | +import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION; |
| 16 | +import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION__ROLES; |
| 17 | +import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION__SCRIPT_VARIANT; |
| 18 | +import static java.util.Map.entry; |
| 19 | + |
| 20 | +import java.text.MessageFormat; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Map; |
| 23 | + |
| 24 | +import org.eclipse.core.runtime.IProgressMonitor; |
| 25 | + |
| 26 | +import com._1c.g5.v8.dt.metadata.mdclass.Configuration; |
| 27 | +import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant; |
| 28 | +import com.e1c.g5.v8.dt.check.CheckComplexity; |
| 29 | +import com.e1c.g5.v8.dt.check.ICheckParameters; |
| 30 | +import com.e1c.g5.v8.dt.check.components.BasicCheck; |
| 31 | +import com.e1c.g5.v8.dt.check.components.TopObjectFilterExtension; |
| 32 | +import com.e1c.g5.v8.dt.check.settings.IssueSeverity; |
| 33 | +import com.e1c.g5.v8.dt.check.settings.IssueType; |
| 34 | +import com.e1c.v8codestyle.check.StandardCheckExtension; |
| 35 | +import com.e1c.v8codestyle.internal.md.CorePlugin; |
| 36 | +import com.e1c.v8codestyle.md.check.SkipAdoptedInExtensionMdObjectExtension; |
| 37 | + |
| 38 | +/** |
| 39 | + * The check that the configuration has required roles. |
| 40 | + * |
| 41 | + * @author Aleksey Kalugin |
| 42 | + * |
| 43 | + */ |
| 44 | +public class RoleMissingCheck |
| 45 | + extends BasicCheck<Object> |
| 46 | +{ |
| 47 | + private static final String CHECK_ID = "role-missing"; //$NON-NLS-1$ |
| 48 | + |
| 49 | + //@formatter:off |
| 50 | + private static final Map<ScriptVariant, List<String>> ROLE_NAMES = Map.ofEntries( |
| 51 | + entry(ScriptVariant.ENGLISH, |
| 52 | + List.of("FullAccess", "SystemAdministrator", "InteractiveOpenExternalReportsAndDataProcessors")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 53 | + entry(ScriptVariant.RUSSIAN, |
| 54 | + List.of("ПолныеПрава", "АдминистраторСистемы", "ИнтерактивноеОткрытиеВнешнихОтчетовИОбработок")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 55 | + ); |
| 56 | + //@formatter:on |
| 57 | + |
| 58 | + @Override |
| 59 | + protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters, |
| 60 | + IProgressMonitor monitor) |
| 61 | + { |
| 62 | + if (monitor.isCanceled() || !(object instanceof Configuration)) |
| 63 | + { |
| 64 | + return; |
| 65 | + } |
| 66 | + |
| 67 | + var configuration = (Configuration)object; |
| 68 | + var roles = configuration.getRoles(); |
| 69 | + for (var roleName : ROLE_NAMES.get(configuration.getScriptVariant())) |
| 70 | + { |
| 71 | + if (monitor.isCanceled()) { |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + if (roles.stream().noneMatch(role -> roleName.equals(role.getName()))) |
| 76 | + { |
| 77 | + resultAceptor.addIssue( |
| 78 | + MessageFormat.format(Messages.RoleMissing_message, roleName), |
| 79 | + CONFIGURATION__ROLES); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public String getCheckId() |
| 86 | + { |
| 87 | + return CHECK_ID; |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + protected void configureCheck(CheckConfigurer builder) |
| 92 | + { |
| 93 | + builder.title(Messages.RoleMissing_title) |
| 94 | + .description(Messages.RoleMissing_description) |
| 95 | + .complexity(CheckComplexity.NORMAL) |
| 96 | + .severity(IssueSeverity.TRIVIAL) |
| 97 | + .issueType(IssueType.WARNING) |
| 98 | + .extension(new TopObjectFilterExtension()) |
| 99 | + .extension(new StandardCheckExtension(488, getCheckId(), CorePlugin.PLUGIN_ID)) |
| 100 | + .extension(new SkipAdoptedInExtensionMdObjectExtension()) |
| 101 | + .topObject(CONFIGURATION) |
| 102 | + .checkTop() |
| 103 | + .features(CONFIGURATION__SCRIPT_VARIANT, CONFIGURATION__ROLES); |
| 104 | + } |
| 105 | + |
| 106 | +} |
0 commit comments