use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class Data method findRow.
public Row findRow(long eleemntId) {
long id = engine.getQualifierIdForElement(eleemntId);
Qualifier qualifier = getQualifier(id);
if (qualifier == null)
return null;
return (Row) getRowSet(id).findRow(eleemntId);
}
use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class Data method getQualifier.
public Qualifier getQualifier(long qualifierId) {
Qualifier qualifier = qualifierByIds.get(qualifierId);
if (qualifier == null) {
qualifier = engine.getQualifier(qualifierId);
if (qualifier == null)
return null;
qualifierByIds.put(qualifierId, qualifier);
}
return qualifier;
}
use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class ServerAccessRules method canDeleteQualifier.
@Override
public boolean canDeleteQualifier(long qualifierId) {
boolean admin = isAdmin();
if (admin)
return true;
Qualifier q = engine.getQualifier(qualifierId);
if (q == null)
return false;
if (q.isSystem())
return true;
return admin;
}
use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method setBinaryAttribute.
// @SuppressWarnings("unused")
@Override
public boolean setBinaryAttribute(final long elementId, final long attributeId, final Transaction transaction) {
if (elementId >= 0) {
long qualifierId = getQualifierIdForElement(elementId);
Qualifier qualifier = getQualifier(qualifierId);
boolean attr = false;
if ((qualifier == null) && (Metadata.DEBUG)) {
System.err.println("WARNING: Can not set attribute for not existing element");
throw new RuntimeException("WARNING: Can not set attribute for not existing element");
}
for (Attribute attribute : qualifier.getAttributes()) {
if (attributeId == attribute.getId()) {
attr = true;
}
}
for (Attribute attribute : qualifier.getSystemAttributes()) {
if (attributeId == attribute.getId()) {
attr = true;
}
}
if (!attr) {
throw new RuntimeException("Attribute with id: " + attributeId + " not found for qualifier: " + qualifier);
}
}
Attribute propertyAttribute = getAttribute(attributeId);
if (elementId < 0l && propertyAttribute != null && propertyAttribute.getAttributeType().toString().equals("Core.Variant")) {
} else if (!getAccessor().canUpdateElement(elementId, attributeId))
return false;
process(transaction.getDelete(), elementId, attributeId);
process(transaction.getUpdate(), elementId, attributeId);
process(transaction.getSave(), elementId, attributeId);
if (elementId >= 0 && propertyAttribute.getAttributeType().getTypeName().equals("ElementList") && propertyAttribute.getAttributeType().getPluginName().equals("Core")) {
try {
setElistFix(transaction);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
return (Boolean) template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
executeTransaction(transaction, connection);
long branch = getActiveBranchId();
Boolean res = Boolean.FALSE;
if (branch > 0l) {
PreparedStatement ps = template.getPreparedStatement("SELECT branch_id FROM " + prefix + "attributes_data_metadata WHERE branch_id=? AND attribute_id=? AND element_id=?", true);
ps.setLong(1, branch);
ps.setLong(2, attributeId);
ps.setLong(3, elementId);
ResultSet rs = ps.executeQuery();
if (!rs.next() && !transaction.isRemoveBranchInfo()) {
rs.close();
ps = template.getPreparedStatement("INSERT INTO " + prefix + "attributes_data_metadata(element_id, attribute_id, branch_id) VALUES(?, ?, ?)", true);
ps.setLong(1, elementId);
ps.setLong(2, attributeId);
ps.setLong(3, branch);
ps.execute();
res = Boolean.TRUE;
} else {
rs.close();
if (transaction.isRemoveBranchInfo()) {
ps = template.getPreparedStatement("DELETE FROM " + prefix + "attributes_data_metadata WHERE branch_id=? AND attribute_id=? AND element_id=?", false);
ps.setLong(1, branch);
ps.setLong(2, attributeId);
ps.setLong(3, elementId);
ps.execute();
ps.close();
}
}
}
return res;
}
});
}
use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method setElementQualifier.
@Override
public void setElementQualifier(final long elementId, final long qualifierId) {
throwExaptionIfNotCan(getAccessor().canDeleteElements(new long[] { elementId }), "Can not update element's qualifier.");
throwExaptionIfNotCan(getAccessor().canCreateElement(qualifierId), "Can not update element's qualifier.");
Element element = getElement(elementId);
Qualifier current = getQualifier(element.getQualifierId());
Qualifier newQualifier = getQualifier(qualifierId);
final List<Attribute> attrs = new ArrayList<Attribute>();
addNotPresentAttributes(current.getAttributes(), newQualifier.getAttributes(), attrs);
addNotPresentAttributes(current.getSystemAttributes(), newQualifier.getSystemAttributes(), attrs);
template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
Transaction[] transactions = getAttributesWhatWillBeDeleted(elementId, attrs);
for (Transaction transaction : transactions) {
executeTransaction(transaction, connection);
}
PreparedStatement ps = connection.prepareStatement("UPDATE " + prefix + "elements SET QUALIFIER_ID=? WHERE ELEMENT_ID=?");
ps.setLong(1, qualifierId);
ps.setLong(2, elementId);
ps.execute();
ps.close();
return null;
}
});
}
Aggregations