本文整理汇总了Java中com.jamonapi.MonitorFactory.start方法的典型用法代码示例。如果您正苦于以下问题:Java MonitorFactory.start方法的具体用法?Java MonitorFactory.start怎么用?Java MonitorFactory.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jamonapi.MonitorFactory
的用法示例。
在下文中一共展示了MonitorFactory.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeUnderTrace
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
/**
* Wraps the invocation with a JAMon Monitor and writes the current
* performance statistics to the log (if enabled).
* @see com.jamonapi.MonitorFactory#start
* @see com.jamonapi.Monitor#stop
*/
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
String name = createInvocationTraceName(invocation);
MonKey key = new MonKeyImp(name, name, "ms.");
Monitor monitor = MonitorFactory.start(key);
try {
return invocation.proceed();
}
catch (Throwable ex) {
trackException(key, ex);
throw ex;
}
finally {
monitor.stop();
if (!this.trackAllInvocations || isLogEnabled(logger)) {
logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor);
}
}
}
示例2: profileInvocation
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
public Object profileInvocation(ProceedingJoinPoint pjp) throws Throwable {
if (logger.isDebugEnabled()) {
logger.debug("profiling call for method" + pjp.toLongString());
}
Monitor mon = MonitorFactory.start(createMonitorName(pjp));
try {
return pjp.proceed();
} finally {
mon.stop();
long now = System.currentTimeMillis();
if (now - lastOutput > outputInterval) {
lastOutput = now;
try {
outputStats();
} catch (IOException ioe) {
logger.warn("error writing to '" + getReportOutputLocation() + "'", ioe);
}
}
}
}
示例3: invokeUnderTrace
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
/**
* Wraps the invocation with a JAMon Monitor and writes the current
* performance statistics to the log (if enabled).
* @see com.jamonapi.MonitorFactory#start
* @see com.jamonapi.Monitor#stop
*/
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
String name = createInvocationTraceName(invocation);
Monitor monitor = MonitorFactory.start(name);
try {
return invocation.proceed();
}
finally {
monitor.stop();
if (!this.trackAllInvocations || isLogEnabled(logger)) {
logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor);
}
}
}
示例4: storeItemWithProfileInternal
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
private Response storeItemWithProfileInternal(String apiKey, String tenantID, String itemID, String itemType,
String itemDescription, String itemUrl, String itemImageUrl, String profile) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_STORE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantID);
if (checkParameters(coreTenantId, itemID, itemDescription, itemUrl, errorMessages) && checkParameterProfile(profile, errorMessages)) {
itemType = checkItemType(itemType, coreTenantId, Item.DEFAULT_STRING_ITEM_TYPE, errorMessages);
if (itemType != null) {
itemDAO.insertOrUpdate(coreTenantId, itemID, itemType, itemDescription, itemUrl, itemImageUrl);
if (profileService.storeProfile(coreTenantId, itemID, itemType, profile))
responseObject.add(MSG.PROFILE_SAVED);
else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
}
} catch (IllegalArgumentException illegalArgumentException) {
if (illegalArgumentException.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
} catch (RuntimeException runtimeException) {
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_STORE, null);
mon.stop();
return response;
}
示例5: pushFieldInternal
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
private Response pushFieldInternal(String apiKey, String tenantID, String itemID, String itemType, String path, String value) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_FIELD_STORE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
if (checkParameters(apiKey, tenantID, itemID, itemType, errorMessages) &&
checkParameterValue(value, errorMessages)) {
Integer coreTenantID = operatorDAO.getTenantId(apiKey, tenantID);
if (coreTenantID == null)
errorMessages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
else {
if (profileService.pushToArrayField(
coreTenantID, itemID, itemType,
path, value))
responseObject.add(MSG.PROFILE_FIELD_SAVED);
else
errorMessages.add(MSG.PROFILE_FIELD_NOT_SAVED);
}
}
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
if (e.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else {
errorMessages.add(MSG.PROFILE_FIELD_NOT_SAVED.append(e.getMessage()));
}
} else {
errorMessages.add(MSG.OPERATION_FAILED.append(
"Exception: " + e.getMessage()));
}
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_FIELD_PUSH, null);
mon.stop();
return response;
}
示例6: itemsBasedOnViewingHistory
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
@IOLog
@Profiled
@Override
public Recommendation itemsBasedOnViewingHistory(Integer tenantId, String userId, Session session,
String consideredItemType, Integer numberOfLastActionsConsidered,
String assocType, String requestedItemType,
Integer numberOfRecommendations) throws EasyRecRestException {
Recommendation rec;
RemoteTenant remoteTenant = remoteTenantDAO.get(tenantId);
Monitor monCore = MonitorFactory.start(JAMON_REST_RECS_FOR_USER);
RecommendationVO<Integer, String> recommendation =
domainRecommenderService.itemsBasedOnViewingHistory(
tenantId, idMappingDAO.lookup(userId), null, // no sessionId needed
consideredItemType, numberOfLastActionsConsidered, assocType, requestedItemType);
monCore.stop();
List<Item> items = idMappingService.mapRecommendedItems(recommendation, remoteTenant,
idMappingDAO.lookup(userId), session,
numberOfRecommendations); // session needed for building backtracking url (session.getRequest())
rec = new Recommendation(remoteTenant.getStringId(), WS.ACTION_RECOMMENDATIONS_FOR_USER, userId, null,
// no sessionId needed
null, // no base item needed
items);
return rec;
}
示例7: importitem
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
@GET
@Path("/importitem")
public Response importitem(@PathParam("type") String type,
@QueryParam("token") String token,
@QueryParam("tenantid") String tenantId,
@QueryParam("itemid") String itemId,
@QueryParam("itemdescription") String itemDescription,
@QueryParam("itemurl") String itemUrl,
@QueryParam("itemimageurl") String itemImageUrl,
@QueryParam("itemtype") String itemType,
@QueryParam("callback") String callback,
@QueryParam("apikey") String apiKey)
throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_IMPORT_ITEM);
if (easyrecSettings.getSecuredAPIMethods().contains("importitem")) {
Operator o = operatorDAO.getOperatorFromToken(token);
if (o == null)
exceptionResponse(WS.ACTION_IMPORT_ITEM, MSG.WRONG_TOKEN, type, callback);
else
apiKey = o.getApiKey();
}
// Collect a List of messages for the user to understand,
// what went wrong (e.g. Wrong API key).
List<Message> messages = new ArrayList<>();
Integer coreTenantId = null;
coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
checkParameters(coreTenantId, itemId, itemDescription, itemUrl, messages);
if (messages.size() > 0) {
if (type.endsWith(WS.RESPONSE_TYPE_PATH_JSON))
throw new EasyRecException(messages, WS.ACTION_IMPORT_ITEM, WS.RESPONSE_TYPE_JSON, callback);
else
throw new EasyRecException(messages, WS.ACTION_IMPORT_ITEM);
}
itemType = checkItemType(itemType, type, coreTenantId, tenantId, WS.ACTION_IMPORT_ITEM, callback);
itemDAO.insertOrUpdate(coreTenantId, itemId, itemType, itemDescription, itemUrl, itemImageUrl);
ResponseItem respItem = new ResponseItem(tenantId, WS.ACTION_IMPORT_ITEM, null, null, null,
itemDAO.get(remoteTenantDAO.get(coreTenantId), itemId, itemType));
mon.stop();
if (type.endsWith(WS.RESPONSE_TYPE_PATH_JSON)) {
if (callback != null)
return Response.ok(new JSONPObject(callback, respItem), WS.RESPONSE_TYPE_JSCRIPT)
.build();
else
return Response.ok(respItem, WS.RESPONSE_TYPE_JSON).build();
} else
return Response.ok(respItem, WS.RESPONSE_TYPE_XML).build();
}
示例8: actionHistoryForUser
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
@GET
@Path("/actionhistoryforuser")
public Response actionHistoryForUser(@PathParam("type") String type, @QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantId, @QueryParam("userid") String userId,
@QueryParam("numberOfResults") Integer numberOfResults,
@QueryParam("offset") @DefaultValue("0") Integer offset,
@QueryParam("requesteditemtype") String requestedItemType,
@QueryParam("callback") String callback,
@QueryParam("actiontype") @DefaultValue(TypeMappingService.ACTION_TYPE_VIEW) String actiontype,
@QueryParam("withProfile") @DefaultValue("false") boolean withProfile,
@QueryParam("token") String token)
throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_ACTIONHISTORY);
if (easyrecSettings.getSecuredAPIMethods().contains("actionhistoryforuser")) {
Operator o = operatorDAO.getOperatorFromToken(token);
if (o == null)
exceptionResponse(WS.ACTION_HISTORY, MSG.WRONG_TOKEN, type, callback);
else
apiKey = o.getApiKey();
}
Recommendation rec = null;
Session session = new Session(null, request);
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
if (coreTenantId == null)
exceptionResponse(WS.ACTION_HISTORY, MSG.TENANT_WRONG_TENANT_APIKEY, type, callback);
RemoteTenant remoteTenant = remoteTenantDAO.get(coreTenantId);
if (remoteTenant.isMaxActionLimitExceeded())
exceptionResponse(WS.ACTION_HISTORY, MSG.MAXIMUM_ACTIONS_EXCEEDED, type, callback);
if (Strings.isNullOrEmpty(userId))
exceptionResponse(WS.ACTION_HISTORY, MSG.USER_NO_ID, type, callback);
requestedItemType = checkItemType(requestedItemType, type, coreTenantId, tenantId, WS.ACTION_HISTORY, callback, null);
if (typeMappingService.getIdOfActionType(coreTenantId, actiontype) == null) {
exceptionResponse(WS.ACTION_HISTORY, MSG.OPERATION_FAILED.append(String.format(" actionType %s not found for tenant %s", actiontype, tenantId)), type, callback);
}
if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS))
numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;
if (rec == null || rec.getRecommendedItems().isEmpty()) {
try {
rec = shopRecommenderService.actionHistory(coreTenantId, userId, session, actiontype,
requestedItemType, numberOfResults + 5, numberOfResults,
offset); // +5 to compensate for inactive items
if (withProfile) {
addProfileDataToItems(rec);
}
} catch (EasyRecRestException sre) {
exceptionResponse(WS.ACTION_HISTORY, sre.getMessageObject(), type, callback);
}
}
mon.stop();
if (type.endsWith(WS.RESPONSE_TYPE_PATH_JSON)) {
if (callback != null)
return Response.ok(new JSONPObject(callback, rec), WS.RESPONSE_TYPE_JSCRIPT).build();
else
return Response.ok(rec, WS.RESPONSE_TYPE_JSON).build();
} else
return Response.ok(rec, WS.RESPONSE_TYPE_XML).build();
}
示例9: purchaseItem
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
/**
* This procedure tells the ProfilerController that an Item is purchased.
* Note:
* A SessionId is always required. In case no userId is given the sessionId
* is used a the userId instead.
*/
@IOLog
@Profiled
@Override
public Item purchaseItem(RemoteTenant remoteTenant, String userId, String itemId, String itemType,
String itemDescription, String itemUrl, String itemImageUrl, Date actionTime,
Session session, String actionInfo) {
Item item = itemDAO.get(remoteTenant, itemId, itemType);
if (item == null) {
item = itemDAO.add(remoteTenant.getId(), itemId, itemType, itemDescription, itemUrl, itemImageUrl);
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().
append("<[email protected]").
append(remoteTenant.getId()).
append("> ").
append(itemType).
append(" ").
append(itemDescription).
append(" (id:").
append(itemId).
append(")").toString());
}
}
if (item != null && item.isActive()) {
// if userid is empty use sessionid instead of the userid
userId = Strings.isNullOrEmpty(userId) ? session.getSessionId() : userId;
Monitor monCore = MonitorFactory.start(JAMON_REST_BUY_CORE);
if (actionTime == null) {
domainActionService
.purchaseItem(remoteTenant.getId(), idMappingDAO.lookup(userId), session.getSessionId(),
session.getIp(),
new ItemVO<>(remoteTenant.getId(), idMappingDAO.lookup(itemId),
itemType), actionInfo);
} else {
domainActionService
.purchaseItem(remoteTenant.getId(), idMappingDAO.lookup(userId), session.getSessionId(),
session.getIp(),
new ItemVO<>(remoteTenant.getId(), idMappingDAO.lookup(itemId),
itemType), actionInfo, actionTime);
}
monCore.stop();
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().
append("<[email protected]").
append(remoteTenant.getId()).
append("> ").
append(userId).
append(" view ").
append(itemDescription).
append(" (id:").
append(itemId).
append(")").toString());
}
}
return item;
}
示例10: viewItem
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
/**
* This procedure tells the ProfilerController that an Item is viewed.
* Note:
* A SessionId is always required. In case no userId is given the sessionId
* is used a the userId instead.
*/
@IOLog
@Profiled
@Override
public Item viewItem(RemoteTenant remoteTenant, String userId, String itemId, String itemType,
String itemDescription, String itemUrl, String itemImageUrl, Date actionTime,
Session session, String actionInfo) {
Item item = itemDAO.get(remoteTenant, itemId, itemType);
if (item == null) {
item = itemDAO.add(remoteTenant.getId(), itemId, itemType, itemDescription, itemUrl, itemImageUrl);
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().
append("<[email protected]").
append(remoteTenant.getId()).
append("> ").
append(itemType).
append(" ").
append(itemDescription).
append(" (id:").
append(itemId).
append(")").toString());
}
}
if (item != null && item.isActive()) {
// if userid is empty use sessionid instead of the userid
userId = Strings.isNullOrEmpty(userId) ? session.getSessionId() : userId;
Monitor monCore = MonitorFactory.start(JAMON_REST_VIEW_CORE);
if (actionTime == null) {
domainActionService.viewItem(remoteTenant.getId(), idMappingDAO.lookup(userId), session.getSessionId(),
session.getIp(),
new ItemVO<>(remoteTenant.getId(), idMappingDAO.lookup(itemId),
itemType), actionInfo);
} else {
domainActionService.viewItem(remoteTenant.getId(), idMappingDAO.lookup(userId), session.getSessionId(),
session.getIp(),
new ItemVO<>(remoteTenant.getId(), idMappingDAO.lookup(itemId),
itemType), actionInfo, actionTime);
}
monCore.stop();
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().
append("<[email protected]").
append(remoteTenant.getId()).
append("> ").
append(userId).
append(" view ").
append(itemDescription).
append(" (id:").
append(itemId).
append(")").toString());
}
}
return item;
}
示例11: rateItem
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
/**
* This procedure tells the ProfilerController that an Item is rated
* with a given value.
* Note:
* A SessionId is always required. In case no userId is given the sessionId
* is used a the userId instead.
*/
@IOLog
@Profiled
@Override
public Item rateItem(RemoteTenant remoteTenant, String userId, String itemId, String itemType,
String itemDescription, String itemUrl, String itemImageUrl, Integer ratingValue,
Date actionTime, Session session, String actionInfo) {
Item item = itemDAO.get(remoteTenant, itemId, itemType);
if (item == null) {
item = itemDAO.add(remoteTenant.getId(), itemId, itemType, itemDescription, itemUrl, itemImageUrl);
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().
append("<[email protected]").
append(remoteTenant.getId()).
append("> ").
append(itemType).
append(" ").
append(itemDescription).
append(" (id:").
append(itemId).
append(")").toString());
}
}
if (item != null && item.isActive()) {
// if userid is empty use sessionid instead of the userid
userId = Strings.isNullOrEmpty(userId) ? session.getSessionId() : userId;
Monitor monCore = MonitorFactory.start(JAMON_REST_RATE_CORE);
if (actionTime == null) {
domainActionService.rateItem(remoteTenant.getId(), idMappingDAO.lookup(userId), session.getSessionId(),
session.getIp(),
new ItemVO<>(remoteTenant.getId(), idMappingDAO.lookup(itemId),
itemType), ratingValue, actionInfo);
} else {
domainActionService.rateItem(remoteTenant.getId(), idMappingDAO.lookup(userId), session.getSessionId(),
session.getIp(),
new ItemVO<>(remoteTenant.getId(), idMappingDAO.lookup(itemId),
itemType), ratingValue, actionInfo, actionTime);
}
monCore.stop();
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().
append("<[email protected]").
append(remoteTenant.getId()).
append("> ").
append(userId).
append(" view ").
append(itemDescription).
append(" (id:").
append(itemId).
append(")").toString());
}
}
return item;
}
示例12: sendAction
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
/**
* This procedure tells the ProfilerController that an Item is rated
* with a given value.
* Note:
* A SessionId is always required. In case no userId is given the sessionId
* is used as the userId instead.
*/
@IOLog
@Profiled
@Override
public Item sendAction(RemoteTenant remoteTenant, String userId, String itemId, String itemType,
String itemDescription, String itemUrl, String itemImageUrl, String actionType, Integer actionValue,
Date actionTime, Session session, String actionInfo) {
Item item = itemDAO.get(remoteTenant, itemId, itemType);
if (item == null) {
item = itemDAO.add(remoteTenant.getId(), itemId, itemType, itemDescription, itemUrl, itemImageUrl);
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().
append("<[email protected]").
append(remoteTenant.getId()).
append("> ").
append(itemType).
append(" ").
append(itemDescription).
append(" (id:").
append(itemId).
append(")").toString());
}
}
if (item != null && item.isActive()) {
// if userid is empty use sessionid instead of the userid
userId = Strings.isNullOrEmpty(userId) ? session.getSessionId() : userId;
Monitor monCore = MonitorFactory.start(JAMON_REST_SENDACTION_CORE);
if (actionTime == null) {
domainActionService.insertAction(remoteTenant.getId(), idMappingDAO.lookup(userId), session.getSessionId(),
session.getIp(),
new ItemVO<>(remoteTenant.getId(), idMappingDAO.lookup(itemId),
itemType), actionType, actionValue, actionInfo);
} else {
domainActionService.insertAction(remoteTenant.getId(), idMappingDAO.lookup(userId), session.getSessionId(),
session.getIp(),
new ItemVO<>(remoteTenant.getId(), idMappingDAO.lookup(itemId),
itemType), actionType, actionValue, actionInfo, actionTime);
}
monCore.stop();
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().
append("<[email protected]").
append(remoteTenant.getId()).
append("> ").
append(userId).
append(" view ").
append(itemDescription).
append(" (id:").
append(itemId).
append(")").toString());
}
}
return item;
}
示例13: deleteProfile
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
/**
* This method deletes the profile of the item defined by the tenantID,
* itemID and the itemTypeID
*
* @param apiKey the apiKey which admits access to the API
* @param tenantID the tenantID of the item whose profile will be deleted
* @param itemID the itemID if the item whose profile will be deleted
* @param itemType the itemType of the item whose profile will be deleted
* @return a response object containing information about the success of the operation
*/
@DELETE
@Path("/delete")
public Response deleteProfile(@QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantID,
@QueryParam("itemid") String itemID,
@DefaultValue("ITEM") @QueryParam("itemtype") String itemType) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_DELETE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
if (checkParameters(apiKey, tenantID, itemID, itemType, errorMessages)) {
Integer coreTenantID = operatorDAO.getTenantId(apiKey, tenantID);
if (coreTenantID == null)
errorMessages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
else {
if (profileService.deleteProfile(coreTenantID, itemID, itemType))
responseObject.add(MSG.PROFILE_DELETED);
else
errorMessages.add(MSG.PROFILE_NOT_DELETED);
}
}
} catch (IllegalArgumentException illegalArgumentException) {
if (illegalArgumentException.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else
errorMessages.add(MSG.PROFILE_NOT_DELETED.append(illegalArgumentException.getMessage()));
} catch (ItemNotFoundException itemNotFoundException) {
errorMessages.add(MSG.ITEM_NOT_EXISTS);
} catch (RuntimeException runtimeException) {
errorMessages.add(MSG.PROFILE_NOT_DELETED);
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_DELETE, null);
mon.stop();
return response;
}
示例14: loadProfile
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
/**
* This method returns the profile of the item defined by the tenantID,
* itemID and the itemTypeID
*
* @param apiKey the apiKey which admits access to the API
* @param tenantID the tenantID of the item whose profile will be returned
* @param itemID the itemID if the item whose profile will be returned
* @param itemType the itemType of the item whose profile will be returned
* @param callback
* @return a response object containing the wanted profile
*/
@GET
@Path("/load")
public Response loadProfile(@QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantID,
@QueryParam("itemid") String itemID,
@DefaultValue("ITEM") @QueryParam("itemtype") String itemType,
@QueryParam("callback") String callback) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_LOAD);
List<Message> errorMessages = new ArrayList<>();
Object responseObject = null;
try {
if (checkParameters(apiKey, tenantID, itemID, itemType, errorMessages)) {
Integer coreTenantID = operatorDAO.getTenantId(apiKey, tenantID);
if (coreTenantID == null)
errorMessages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
else {
String profile = profileService.getProfile(coreTenantID, itemID, itemType);
if (profile != null)
responseObject = new ResponseProfileField("profile/load", tenantID, itemID, itemType, "profile", profile);
else
errorMessages.add(MSG.PROFILE_NOT_LOADED);
}
}
} catch (IllegalArgumentException illegalArgumentException) {
if (illegalArgumentException.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else
errorMessages.add(MSG.PROFILE_NOT_LOADED.append(illegalArgumentException.getMessage()));
} catch (ItemNotFoundException itemNotFoundException) {
errorMessages.add(MSG.ITEM_NOT_EXISTS);
} catch (RuntimeException runtimeException) {
errorMessages.add(MSG.PROFILE_NOT_LOADED);
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_LOAD, callback);
mon.stop();
return response;
}
示例15: deleteField
import com.jamonapi.MonitorFactory; //导入方法依赖的package包/类
/**
* This method deletes a specific field of the profile which belongs to the item
* defined by the tenantID, itemID and the itemTypeID. The field can be addressed
* by a XPath expression
*
* @param apiKey the apiKey which admits access to the API
* @param tenantID the tenantID of the addressed item
* @param itemID the itemID if the addressed item
* @param itemType the itemType of the addressed item
* @param path
* @return a response object containing information about the success of the operation
*/
@DELETE
@Path("/field/delete")
public Response deleteField(@QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantID,
@QueryParam("itemid") String itemID,
@DefaultValue("ITEM") @QueryParam("itemtype") String itemType,
@QueryParam("path") String path) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_FIELD_DELETE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
if (checkParameters(apiKey, tenantID, itemID, itemType, errorMessages) &&
checkParameterField(path, errorMessages)) {
Integer coreTenantID = operatorDAO.getTenantId(apiKey, tenantID);
if (coreTenantID == null) {
errorMessages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
}
else {
if (profileService.deleteProfileField(coreTenantID, itemID, itemType, path))
responseObject.add(MSG.PROFILE_FIELD_DELETED);
else
errorMessages.add(MSG.PROFILE_FIELD_NOT_DELETED);
}
}
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
if (e.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else
errorMessages.add(MSG.PROFILE_FIELD_NOT_DELETED.append(e.getMessage()));
}
else if (e instanceof ItemNotFoundException) {
errorMessages.add(MSG.ITEM_NOT_EXISTS.append(
" ItemNotFoundException: " + e.getMessage()));
} else {
errorMessages.add(MSG.OPERATION_FAILED.append(
"Exception: " + e.getMessage()));
}
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_FIELD_DELETE, null);
mon.stop();
return response;
}