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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations