@@ -0,0 +1,3435 @@
+/*%0A * Copyright 2003 - 2022 The eFaps Team%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A *%0A */%0A%0Apackage org.efaps.esjp.admin.util;%0A%0Aimport java.sql.SQLException;%0Aimport java.sql.Statement;%0A%0Aimport org.efaps.admin.datamodel.Type;%0Aimport org.efaps.admin.event.Parameter;%0Aimport org.efaps.admin.program.esjp.EFapsApplication;%0Aimport org.efaps.admin.program.esjp.EFapsUUID;%0Aimport org.efaps.db.Context;%0Aimport org.efaps.db.transaction.ConnectionResource;%0Aimport org.efaps.util.EFapsException;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A@EFapsUUID(%22d38d19fc-dce2-4026-aaac-d83250f4fdd0%22)%0A@EFapsApplication(%22eFaps-Kernel%22)%0Apublic class AssociationUtil%0A    extends AbstractUtil%0A%7B%0A    private static final Logger LOG = LoggerFactory.getLogger(AssociationUtil.class);%0A%0A    public void assignAssociation(final Parameter _parameter)%0A        throws EFapsException%0A    %7B%0A        if (checkAccess()) %7B%0A            final String%5B%5D keys = _parameter.getParameterValues(%22keyField%22);%0A            final String%5B%5D values = _parameter.getParameterValues(%22valueField%22);%0A            int i = 0;%0A            String typeStr = null;%0A            String associationId = null;%0A            for (final var key: keys) %7B%0A                if (key.equals(%22type%22)) %7B%0A                    typeStr = values%5Bi%5D;%0A                %7D%0A                if (key.equals(%22associationId%22)) %7B%0A                    associationId = values%5Bi%5D;%0A                %7D%0A                i++;%0A            %7D%0A            LOG.info(%22assignAssociation =%3E  type: '%7B%7D', associationId: '%7B%7D'%22, typeStr, associationId);%0A%0A            final var type = Type.get(typeStr);%0A%0A            final Context context = Context.getThreadContext();%0A            final StringBuilder cmd = new StringBuilder()%0A                            .append(%22UPDATE %22)%0A                            .append(type.getMainTable().getSqlTable())%0A                            .append(%22 SET %22)%0A                            .append(type.getAssociationAttribute().getSqlColNames().get(0))%0A                            .append(%22 = %22)%0A                            .append(associationId)%0A                            .append(%22 WHERE %22)%0A                            .append(type.getAssociationAttribute().getSqlColNames().get(0))%0A                            .append(%22 IS NULL%22);%0A%0A            ConnectionResource con = null;%0A            try %7B%0A                con = context.getConnectionResource();%0A                LOG.info(%22Updating Association with: %7B%7D%22, cmd);%0A                Statement stmt = null;%0A                try %7B%0A                    stmt = con.createStatement();%0A                    stmt.executeUpdate(cmd.toString());%0A                %7D finally %7B%0A                    if (stmt != null) %7B%0A                        stmt.close();%0A                    %7D%0A                %7D%0A            %7D catch (final SQLException e) %7B%0A                LOG.error(%22sql statement '%22 + cmd.toString() + %22' not executable!%22, e);%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add AssociationUtil