Skip to content

Commit

Permalink
removing compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Apr 12, 2019
1 parent fe6538d commit 2385b81
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 160 deletions.
Expand Up @@ -175,9 +175,16 @@ private void initLayout() {

@Override
public DashboardWidget getObject() {
DashboardWidget ret = getPageBase().getDashboardService().createWidgetData(model.getObject(), task, result);
setDisplay(ret.getDisplay());
return ret;
Task task = getPageBase().createSimpleTask("Get DashboardWidget");
try {
DashboardWidget ret = getPageBase().getDashboardService().createWidgetData(model.getObject(), task, task.getResult());
setDisplay(ret.getDisplay());
return ret;
} catch (SchemaException | CommunicationException | ConfigurationException | SecurityViolationException
| ExpressionEvaluationException | ObjectNotFoundException e) {
LOGGER.error("Couldn't get DashboardWidget with widget " + model.getObject().getIdentifier(), e);
}
return null;
}
};

Expand Down
Expand Up @@ -156,41 +156,6 @@ private List<AuditEventRecordType> listRecords(boolean ordered, long first, long
return auditRecordList;
}

// public static String createQuery(ObjectCollectionType collectionForQuery, Map<String, Object> parameters,
// boolean forDomain, Clock clock) {
// if(collectionForQuery == null) {
// return null;
// }
// AuditSearchType auditSearch = collectionForQuery.getAuditSearch();
// if(auditSearch != null || StringUtils.isNotBlank(auditSearch.getRecordQuery())) {
// Duration interval = auditSearch.getInterval();
// if(interval == null) {
// return auditSearch.getRecordQuery();
// }
// String origQuery = auditSearch.getRecordQuery();
// if(forDomain) {
// origQuery = auditSearch.getDomainQuery();
// if(origQuery == null) {
// return null;
// }
// }
// String [] partsOfQuery = origQuery.split("where");
// if(interval.getSign() == 1) {
// interval = interval.negate();
// }
// Date date = new Date(clock.currentTimeMillis());
// interval.addTo(date);
// String query = partsOfQuery[0] + "where " + TIMESTAMP_VALUE_NAME + " >= " + ":from" + " ";
// parameters.put(PARAMETER_FROM, date);
// if(partsOfQuery.length > 1) {
// query+= "and" +partsOfQuery[1];
// }
// return query;
// }
// return null;
// }


@SuppressWarnings("unused")
@Nullable
public ObjectCollectionType getCollectionForQuery() {
Expand Down
33 changes: 1 addition & 32 deletions gui/admin-gui/src/main/resources/static/less/midpoint-theme.less
Expand Up @@ -1484,37 +1484,6 @@ th.countLabel{
position: relative;
}

.item-different-height{
display: inline-block;
margin: 0 0 1em;
width: 100%;
padding-left: 15px;
padding-right: 15px;
}
@media (max-width: 992px) {
.count-column-sm-2{
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
-moz-column-gap: 0px;
-webkit-column-gap: 0px;
column-gap: 0px;
}
}

@media (min-width: 993px) {
.count-column-lg-4{
-moz-column-count: 4;
-webkit-column-count: 4;
column-count: 4;
-moz-column-gap: 0px;
-webkit-column-gap: 0px;
column-gap: 0px;
}
}

.small-box h3{
white-space: normal;
}


}
Expand Up @@ -38,7 +38,6 @@
public interface DashboardService {

// TODO: check the use of those, do we need them as public in the interface? Move to implementation? Or utils?
public static final String VAR_PROPORTIONAL = "proportional";
public static final String PARAMETER_FROM = "from";

DashboardWidget createWidgetData(DashboardWidgetType widget, Task task, OperationResult result) throws SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, ObjectNotFoundException;
Expand Down
Expand Up @@ -15,6 +15,8 @@
*/
package com.evolveum.midpoint.model.api.util;

import static com.evolveum.midpoint.model.api.util.DashboardUtils.isDataNull;

import java.util.Date;
import java.util.Map;

Expand Down Expand Up @@ -49,7 +51,7 @@ public class DashboardUtils {

private static final String AUDIT_RECORDS_ORDER_BY = " order by aer.timestamp desc";
private static final String TIMESTAMP_VALUE_NAME = "aer.timestamp";
public static final String PARAMETER_FROM = "from";
private static final String PARAMETER_FROM = "from";

public static DashboardWidgetSourceTypeType getSourceType(DashboardWidgetType widget) {
if(isSourceTypeOfDataNull(widget)) {
Expand All @@ -76,6 +78,32 @@ public static boolean isDataNull(DashboardWidgetType widget) {
}
return false;
}

public static boolean isCollectionOfDataNull(DashboardWidgetType widget) {
if(isDataNull(widget)) {
return true;
}
if(widget.getData().getCollection() == null) {
LOGGER.error("Collection of data is not found in widget " + widget.getIdentifier());
return true;
}
return false;
}

public static boolean isCollectionRefOfCollectionNull(DashboardWidgetType widget) {
if (isDataNull(widget)) {
return true;
}
if (isCollectionOfDataNull(widget)) {
return true;
}
ObjectReferenceType ref = widget.getData().getCollection().getCollectionRef();
if (ref == null) {
LOGGER.error("CollectionRef of collection is not found in widget " + widget.getIdentifier());
return true;
}
return false;
}

public static boolean isDataFieldsOfPresentationNullOrEmpty(DashboardWidgetPresentationType presentation) {
if(presentation != null) {
Expand All @@ -101,24 +129,6 @@ public static String getQueryForListRecords(String query) {
return query;
}

// TODO: This is quite a common things, isn't it? Maybe it should rather go to PageBase?
// Ot maybe somehow user ObjectResolver?
public static ObjectType getObjectTypeFromObjectRef(ObjectReferenceType ref, TaskManager taskManager,
PrismContext prismContext, ModelService modelService) {
Task task = taskManager.createTaskInstance("Get object");
Class<ObjectType> type = prismContext.getSchemaRegistry().determineClassForType(ref.getType());
PrismObject<ObjectType> object;

try {
object = modelService.getObject(type,
ref.getOid(), null, task, task.getResult());
return object.asObjectable();
} catch (Exception e) {
LOGGER.error("Couldn't get object from objectRef " + ref, e);
}
return null;
}

public static String createQuery(ObjectCollectionType collectionForQuery, Map<String, Object> parameters,
boolean forDomain, Clock clock) {
if(collectionForQuery == null) {
Expand Down
Expand Up @@ -30,6 +30,7 @@

import com.evolveum.midpoint.audit.api.AuditService;
import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.model.api.CollectionStats;
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
Expand Down Expand Up @@ -75,12 +76,12 @@
/**
* @author skublik
*/
@Component
@Component("dashboardService")
public class DashboardServiceImpl implements DashboardService {

private static final Trace LOGGER = TraceManager.getTrace(DashboardServiceImpl.class);

public static final String VAR_PROPORTIONAL = "proportional";
private static final String VAR_PROPORTIONAL = "proportional";
private static final String VAR_POLICY_SITUATIONS = "policySituations";

@Autowired private TaskManager taskManager;
Expand Down Expand Up @@ -264,29 +265,31 @@ private String generateNumberMessageForCollection(DashboardWidgetType widget, Da
ObjectCollectionType valueCollection = getObjectCollectionType(widget, task, result);
if(valueCollection != null && valueCollection.getType() != null &&
valueCollection.getType().getLocalPart() != null) {
int value = getObjectCount(valueCollection, true, task, result);

int domainValue;
if( valueCollection.getDomain() != null && valueCollection.getDomain().getCollectionRef() != null) {
// ObjectCollectionType domainCollection = (ObjectCollectionType) getObjectCollectionType(widget,
// taskManager, prismContext, modelService);
ObjectReferenceType ref = valueCollection.getDomain().getCollectionRef();
ObjectCollectionType domainCollection = objectResolver.resolve(ref, ObjectCollectionType.class, null, "resolving collection for "+widget, task, result);
if(domainCollection == null) {
return null;
}
CompiledObjectCollectionView compiledCollection = modelInteractionService.compileObjectCollectionView(
valueCollection.asPrismObject(), null, task, task.getResult());
CollectionStats collStats = modelInteractionService.determineCollectionStats(compiledCollection, task, result);

int value = collStats.getObjectCount();//getObjectCount(valueCollection, true, task, result);
Integer domainValue = collStats.getDomainCount();
// if( valueCollection.getDomain() != null && valueCollection.getDomain().getCollectionRef() != null) {
//// ObjectCollectionType domainCollection = (ObjectCollectionType) getObjectCollectionType(widget,
//// taskManager, prismContext, modelService);
// ObjectReferenceType ref = valueCollection.getDomain().getCollectionRef();
// ObjectCollectionType domainCollection = objectResolver.resolve(ref, ObjectCollectionType.class, null, "resolving collection for "+widget, task, result);
// if(domainCollection == null) {
// return null;
// }
// ObjectCollectionType domainCollection = (ObjectCollectionType)WebModelServiceUtils.loadObject(ref,
// getPageBase(), task, task.getResult()).getRealValue();
domainValue = getObjectCount(domainCollection, true, task, result);
} else {
LOGGER.error("Domain or collectionRef in domain is null in collection " + valueCollection.toString());
LOGGER.trace("Using filter for all object based on type");
domainValue = getObjectCount(valueCollection, false, task, result);
}
// domainValue = getObjectCount(domainCollection, true, task, result);
// } else {
// LOGGER.error("Domain or collectionRef in domain is null in collection " + valueCollection.toString());
// LOGGER.trace("Using filter for all object based on type");
// domainValue = getObjectCount(valueCollection, false, task, result);
// }
IntegerStatType statType = generateIntegerStat(value, domainValue);

CompiledObjectCollectionView compiledCollection = modelInteractionService.compileObjectCollectionView(
valueCollection.asPrismObject(), null, task, task.getResult());
Collection<EvaluatedPolicyRule> evalPolicyRules = modelInteractionService.evaluateCollectionPolicyRules(
valueCollection.asPrismObject(), compiledCollection, null, task, task.getResult());
Collection<String> policySituations = new ArrayList<String>();
Expand Down Expand Up @@ -406,14 +409,14 @@ private void evaluateVariation(DashboardWidgetType widget, ExpressionVariables v
}
}

private int getObjectCount(ObjectCollectionType collection, boolean usingFilter, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
List<PrismObject<ObjectType>> values = searchObjectFromCollection(collection, usingFilter, task, result);
if(values != null) {
LOGGER.debug("Return count: {}", values.size());
return values.size();
}
return 0;
}
// private int getObjectCount(ObjectCollectionType collection, boolean usingFilter, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
// List<PrismObject<ObjectType>> values = searchObjectFromCollection(collection, usingFilter, task, result);
// if(values != null) {
// LOGGER.debug("Return count: {}", values.size());
// return values.size();
// }
// return 0;
// }

@Override
public List<PrismObject<ObjectType>> searchObjectFromCollection(ObjectCollectionType collection, boolean usingFilter, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
Expand All @@ -433,32 +436,6 @@ public List<PrismObject<ObjectType>> searchObjectFromCollection(ObjectCollection
return values;
}

private boolean isCollectionOfDataNull(DashboardWidgetType widget) {
if(isDataNull(widget)) {
return true;
}
if(widget.getData().getCollection() == null) {
LOGGER.error("Collection of data is not found in widget " + widget.getIdentifier());
return true;
}
return false;
}

private boolean isCollectionRefOfCollectionNull(DashboardWidgetType widget) {
if (isDataNull(widget)) {
return true;
}
if (isCollectionOfDataNull(widget)) {
return true;
}
ObjectReferenceType ref = widget.getData().getCollection().getCollectionRef();
if (ref == null) {
LOGGER.error("CollectionRef of collection is not found in widget " + widget.getIdentifier());
return true;
}
return false;
}

@Override
public ObjectCollectionType getObjectCollectionType(DashboardWidgetType widget, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (isCollectionRefOfCollectionNull(widget)) {
Expand All @@ -485,21 +462,6 @@ private ObjectType getObjectFromObjectRef(DashboardWidgetType widget, Task task,
return object;
}

public ObjectType getObjectTypeFromObjectRefX(ObjectReferenceType ref) {
Task task = taskManager.createTaskInstance("Get object");
Class<ObjectType> type = prismContext.getSchemaRegistry().determineClassForType(ref.getType());
PrismObject<ObjectType> object;

try {
object = modelService.getObject(type,
ref.getOid(), null, task, task.getResult());
return object.asObjectable();
} catch (Exception e) {
LOGGER.error("Couldn't get object from objectRef " + ref, e);
}
return null;
}

private String getStringExpressionMessage(ExpressionVariables variables,
ExpressionType expression, String shortDes, Task task, OperationResult result) {
if (expression != null) {
Expand Down
Expand Up @@ -341,7 +341,7 @@ private String getBody(DashboardType dashboard, String cssStyle, Task task, Oper
body.append(table.render());
appendSpace(body);
});
body.append("</div");
body.append("</div>");

return body.toString();
}
Expand Down

0 comments on commit 2385b81

Please sign in to comment.