Search in sources :

Example 1 with DeleteStatus

use of com.ramussoft.common.DeleteStatus in project ramus by Vitaliy-Yakovchuk.

the class StatusMessageFormat method toMessage.

public static String toMessage(DeleteStatusList list, GUIFramework framework) {
    StringBuffer sb = new StringBuffer();
    sb.append("<html><body>");
    int i = 0;
    for (DeleteStatus status : list) {
        sb.append(format(status.getPluginAnswer(), framework, status.getPluginName()));
        i++;
        if (i < list.size())
            sb.append("<hr>");
    }
    sb.append("</body></html>");
    return sb.toString();
}
Also used : DeleteStatus(com.ramussoft.common.DeleteStatus)

Example 2 with DeleteStatus

use of com.ramussoft.common.DeleteStatus in project ramus by Vitaliy-Yakovchuk.

the class StandardAttributesPlugin method canDeleteElements.

@Override
public boolean canDeleteElements(long[] elementIds, IEngine engine) {
    Vector<Long> vector = new Vector<Long>();
    for (long elementId : elementIds) {
        long qualifierId = engine.getQualifierIdForElement(elementId);
        Long l = new Long(qualifierId);
        if (vector.indexOf(l) < 0) {
            vector.add(l);
            if (qualifierId == qualifiers.getId()) {
                List<Persistent>[] lists = engine.getBinaryAttribute(elementId, aQualifierId.getId());
                Long long1;
                if (lists[0].size() == 0)
                    long1 = null;
                else
                    long1 = ((LongPersistent) lists[0].get(0)).getValue();
                if (long1 == null)
                    continue;
                if (!rules.canDeleteQualifier(long1)) {
                    DeleteStatus status = new DeleteStatus();
                    status.setDelete(Delete.CAN_NOT);
                    return false;
                }
                continue;
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) DeleteStatus(com.ramussoft.common.DeleteStatus) Vector(java.util.Vector) LongPersistent(com.ramussoft.core.attribute.simple.LongPersistent)

Example 3 with DeleteStatus

use of com.ramussoft.common.DeleteStatus in project ramus by Vitaliy-Yakovchuk.

the class OtherElementPlugin method getElementsDeleteStatus.

@SuppressWarnings("unchecked")
@Override
public DeleteStatus getElementsDeleteStatus(long[] elementIds, IEngine aEngine) {
    if (!(aEngine instanceof IEngineImpl))
        return super.getElementsDeleteStatus(elementIds, aEngine);
    IEngineImpl engine = (IEngineImpl) aEngine;
    JDBCTemplate template = engine.getTemplate();
    String prefix = engine.getPrefix();
    String sql = "SELECT element_name, qualifier_name, attribute_name " + "FROM {0}attribute_other_elements a, {0}attributes b, {0}qualifiers c, {0}elements d " + "WHERE other_element in(" + JDBCTemplate.toSqlArray(elementIds) + ") AND a.attribute_id=b.attribute_id AND d.element_id=a.element_id " + "AND d.qualifier_id=c.qualifier_id AND b.attribute_system=false " + "ORDER BY qualifier_name, attribute_name, element_name";
    List<String> list = template.query(MessageFormat.format(sql, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            String qName = rs.getString(2);
            if (qName.startsWith("TableQualifier_"))
                qName = "{AttributeType.Core.Table}";
            return "<tr><td>" + rs.getString(1) + "</td><td> " + qName + "</td><td> " + rs.getString(3) + "</td></tr>";
        }
    });
    if (list.size() == 0)
        return null;
    DeleteStatus status = new DeleteStatus();
    status.setPluginName("Core");
    StringBuffer sb = new StringBuffer();
    sb.append("<br>");
    sb.append("<table>");
    sb.append("<tr><td><b>{AttributeType.Core.OtherElement}</b></td><td><b>{OtherElement.Qualifier}</b></td><td><b>{OtherElement.Attribute}</b></td></tr>");
    for (String s : list) {
        sb.append(s);
    }
    sb.append("</table>");
    status.setPluginAnswer("{Warning.ElementsUsedAtOtherElements}" + sb.toString());
    return status;
}
Also used : IEngineImpl(com.ramussoft.core.impl.IEngineImpl) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) FindObject(com.ramussoft.common.attribute.FindObject) DeleteStatus(com.ramussoft.common.DeleteStatus) RowMapper(com.ramussoft.jdbc.RowMapper)

Example 4 with DeleteStatus

use of com.ramussoft.common.DeleteStatus in project ramus by Vitaliy-Yakovchuk.

the class AnyToAnyPlugin method getElementsDeleteStatus.

@SuppressWarnings("unchecked")
@Override
public DeleteStatus getElementsDeleteStatus(long[] elementIds, final IEngine engine) {
    final HashMap<Long, Attribute> attributesCache = new HashMap<Long, Attribute>();
    final HashMap<Long, Qualifier> qualifiersCache = new HashMap<Long, Qualifier>();
    JDBCTemplate template = ((IEngineImpl) engine).getTemplate();
    String prefix = ((IEngineImpl) engine).getPrefix();
    StringBuffer sb = JDBCTemplate.toSqlArray(elementIds);
    String sql = "SELECT element_id FROM " + prefix + "attribute_any_to_any_elements WHERE other_element in(" + sb.toString() + ")";
    String gSQL;
    final List<String> functions = new ArrayList<String>();
    gSQL = "SELECT * FROM {0}elements WHERE element_id IN(" + "SELECT other_element FROM {0}attribute_other_elements WHERE element_id in(" + "SELECT element_id FROM {0}attribute_other_elements WHERE other_element in(" + sql + ")) " + "AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true)) ORDER BY element_name";
    template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
            if (elementName.trim().length() > 0 && !functions.contains(elementName))
                functions.add(elementName);
            return null;
        }
    }, new Object[] { IDEF0Plugin.F_SECTOR_FUNCTION }, true);
    gSQL = "SELECT * FROM {0}elements WHERE element_id IN(" + "SELECT other_element FROM {0}attribute_other_elements WHERE element_id in(" + "SELECT element_id FROM {0}attribute_other_elements WHERE other_element in(" + sb + ")) " + "AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true)) ORDER BY element_name";
    template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
            if (elementName.trim().length() > 0 && !functions.contains(elementName))
                functions.add(elementName);
            return null;
        }
    }, new Object[] { IDEF0Plugin.F_SECTOR_FUNCTION }, true);
    gSQL = "SELECT * FROM {0}elements WHERE element_id IN(SELECT parent_element_id FROM {0}attribute_hierarchicals WHERE element_id IN(" + "SELECT element_id FROM {0}attribute_longs WHERE value in(" + sql + ")AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true) " + ")) ORDER BY element_name";
    template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
            if (elementName.trim().length() > 0 && !functions.contains(elementName))
                functions.add(elementName);
            return null;
        }
    }, new Object[] { IDEF0Plugin.F_LINK }, true);
    if (functions.size() > 0) {
        Collections.sort(functions, new Comparator<String>() {

            @Override
            public int compare(String arg0, String arg1) {
                return StringCollator.compare(arg0, arg1);
            }
        });
        DeleteStatus deleteStatus = new DeleteStatus();
        deleteStatus.setPluginName(getName());
        StringBuffer buffer = new StringBuffer();
        for (String s : functions) if (!s.trim().equals("")) {
            buffer.append("<br>");
            buffer.append(s);
        }
        deleteStatus.setPluginAnswer("{Warning.ElementsUsedAtFunctions}" + buffer.toString());
        return deleteStatus;
    }
    return null;
}
Also used : Attribute(com.ramussoft.common.Attribute) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DeleteStatus(com.ramussoft.common.DeleteStatus) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) ResultSet(java.sql.ResultSet) Qualifier(com.ramussoft.common.Qualifier) RowMapper(com.ramussoft.jdbc.RowMapper)

Example 5 with DeleteStatus

use of com.ramussoft.common.DeleteStatus in project ramus by Vitaliy-Yakovchuk.

the class ElementListPlugin method getElementsDeleteStatus.

@SuppressWarnings("unchecked")
@Override
public DeleteStatus getElementsDeleteStatus(long[] elementIds, IEngine aEngine) {
    IEngineImpl engine = (IEngineImpl) aEngine;
    JDBCTemplate template = engine.getTemplate();
    String prefix = engine.getPrefix();
    String sql = "SELECT element_name, qualifier_name, attribute_name " + "FROM {0}attribute_element_lists a, {0}attributes b, {0}qualifiers c, {0}elements d " + "WHERE element2_id in(" + JDBCTemplate.toSqlArray(elementIds) + ") AND a.attribute_id=b.attribute_id AND d.element_id=a.element1_id " + "AND d.qualifier_id=c.qualifier_id AND b.attribute_system=false " + "ORDER BY qualifier_name, attribute_name, element_name";
    List<String> list = template.query(MessageFormat.format(sql, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            return "<tr><td>" + rs.getString(1) + "</td><td> " + rs.getString(2) + "</td><td> " + rs.getString(3) + "</td></tr>";
        }
    });
    sql = "SELECT element_name, qualifier_name, attribute_name " + "FROM {0}attribute_element_lists a, {0}attributes b, {0}qualifiers c, {0}elements d " + "WHERE element1_id in(" + JDBCTemplate.toSqlArray(elementIds) + ") AND a.attribute_id=b.attribute_id AND d.element_id=a.element2_id " + "AND d.qualifier_id=c.qualifier_id AND b.attribute_system=false " + "ORDER BY qualifier_name, attribute_name, element_name";
    List<String> list1 = template.query(MessageFormat.format(sql, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            return "<tr><td>" + rs.getString(1) + "</td><td> " + rs.getString(2) + "</td><td> " + rs.getString(3) + "</td></tr>";
        }
    });
    list.addAll(list1);
    if (list.size() == 0)
        return null;
    DeleteStatus status = new DeleteStatus();
    status.setPluginName("Core");
    StringBuffer sb = new StringBuffer();
    sb.append("<br>");
    sb.append("<table>");
    sb.append("<tr><td><b>{AttributeType.Core.OtherElement}</b></td><td><b>{OtherElement.Qualifier}</b></td><td><b>{OtherElement.Attribute}</b></td></tr>");
    for (String s : list) {
        sb.append(s);
    }
    sb.append("</table>");
    status.setPluginAnswer("{Warning.ElementsUsedAtOtherElements}" + sb.toString());
    return status;
}
Also used : IEngineImpl(com.ramussoft.core.impl.IEngineImpl) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DeleteStatus(com.ramussoft.common.DeleteStatus) RowMapper(com.ramussoft.jdbc.RowMapper)

Aggregations

DeleteStatus (com.ramussoft.common.DeleteStatus)6 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)3 JDBCTemplate (com.ramussoft.jdbc.JDBCTemplate)3 RowMapper (com.ramussoft.jdbc.RowMapper)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Attribute (com.ramussoft.common.Attribute)2 Qualifier (com.ramussoft.common.Qualifier)2 CalculateInfo (com.ramussoft.common.CalculateInfo)1 Element (com.ramussoft.common.Element)1 FindObject (com.ramussoft.common.attribute.FindObject)1 LongPersistent (com.ramussoft.core.attribute.simple.LongPersistent)1 MetaValue (com.ramussoft.eval.MetaValue)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Vector (java.util.Vector)1