@Test public void testRepresentationGadgetDefNotFound() throws ResourceException { Variant variant = context.mock(Variant.class); context.checking(new Expectations() { { oneOf(gadgetMapper).findById(MODULE_ID); will(throwException(new EntityNotFoundException())); } }); sut.represent(variant); context.assertIsSatisfied(); }
@Override public Representation represent(final Variant variant) throws ResourceException { if (moduleId != null && moduleId > 0 && gadgetDefUrl != null) { StringBuilder sb = new StringBuilder(); try { Map<String, GeneralGadgetDefinition> gadgetDefs = new HashMap<String, GeneralGadgetDefinition>(); GadgetDefinition targetGadgetDef = gadgetMapper.findById(moduleId).getGadgetDefinition(); gadgetDefs.put(gadgetDefUrl, targetGadgetDef); List<GadgetMetaDataDTO> gadgetMetaData = gadgetMetaFetcher.getGadgetsMetaData(gadgetDefs); for (GadgetMetaDataDTO currentGMeta : gadgetMetaData) { logger.debug("Retrieved Metadata for Gadget" + targetGadgetDef.getId() + " Author: " + currentGMeta.getAuthor() + " UserPrefsSize: " + currentGMeta.getUserPrefs().size()); buildUserPreferencesUI(currentGMeta, sb); } } catch (Exception ex) { logger.error("Error occurred retrieving User Preferences script", ex); sb.append("var htmlString_" + moduleId + "='';"); sb.append("htmlString_" + moduleId + " += '<div class=\"gadget-preferences\">" + USER_PREFS_ERROR_MESSAGE + "</div>';"); sb.append("gadget_callback_" + moduleId + "(htmlString_" + moduleId + ");"); } logger.debug("Returning the edit settings script: " + sb.toString()); Representation rep = new StringRepresentation(sb.toString(), MediaType.APPLICATION_JAVASCRIPT); rep.setExpirationDate(new Date()); return rep; } else { logger.error("Bad request: Invalid application id passed to endpoint"); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid application id passed to endpoint"); } }
UserPrefsFormUIResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { if (moduleId != null && moduleId > 0 && gadgetDefUrl != null) { StringBuilder sb = new StringBuilder(); try { Map<String, GeneralGadgetDefinition> gadgetDefs = new HashMap<String, GeneralGadgetDefinition>(); GadgetDefinition targetGadgetDef = gadgetMapper.findById(moduleId).getGadgetDefinition(); gadgetDefs.put(gadgetDefUrl, targetGadgetDef); List<GadgetMetaDataDTO> gadgetMetaData = gadgetMetaFetcher.getGadgetsMetaData(gadgetDefs); for (GadgetMetaDataDTO currentGMeta : gadgetMetaData) { logger.debug("Retrieved Metadata for Gadget" + targetGadgetDef.getId() + " Author: " + currentGMeta.getAuthor() + " UserPrefsSize: " + currentGMeta.getUserPrefs().size()); buildUserPreferencesUI(currentGMeta, sb); } } catch (Exception ex) { logger.error("Error occurred retrieving User Preferences script", ex); sb.append("var htmlString_" + moduleId + "='';"); sb.append("htmlString_" + moduleId + " += '<div class=\"gadget-preferences\">" + USER_PREFS_ERROR_MESSAGE + "</div>';"); sb.append("gadget_callback_" + moduleId + "(htmlString_" + moduleId + ");"); } logger.debug("Returning the edit settings script: " + sb.toString()); Representation rep = new StringRepresentation(sb.toString(), MediaType.APPLICATION_JAVASCRIPT); rep.setExpirationDate(new Date()); return rep; } else { logger.error("Bad request: Invalid application id passed to endpoint"); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid application id passed to endpoint"); } } }
UserPrefsFormUIResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { if (moduleId != null && moduleId > 0 && gadgetDefUrl != null) { StringBuilder sb = new StringBuilder(); try { Map<String, GeneralGadgetDefinition> gadgetDefs = new HashMap<String, GeneralGadgetDefinition>(); GadgetDefinition targetGadgetDef = gadgetMapper.findById(moduleId).getGadgetDefinition(); gadgetDefs.put(gadgetDefUrl, targetGadgetDef); List<GadgetMetaDataDTO> gadgetMetaData = gadgetMetaFetcher.getGadgetsMetaData(gadgetDefs); for (GadgetMetaDataDTO currentGMeta : gadgetMetaData) { logger.debug("Retrieved Metadata for Gadget" + targetGadgetDef.getId() + " Author: " + currentGMeta.getAuthor() + " UserPrefsSize: " + currentGMeta.getUserPrefs().size()); buildUserPreferencesUI(currentGMeta, sb); } } catch (Exception ex) { logger.error("Error occurred retrieving User Preferences script", ex); sb.append("var htmlString_" + moduleId + "='';"); sb.append("htmlString_" + moduleId + " += '<div class=\"gadget-preferences\">" + USER_PREFS_ERROR_MESSAGE + "</div>';"); sb.append("gadget_callback_" + moduleId + "(htmlString_" + moduleId + ");"); } logger.debug("Returning the edit settings script: " + sb.toString()); Representation rep = new StringRepresentation(sb.toString(), MediaType.APPLICATION_JAVASCRIPT); rep.setExpirationDate(new Date()); return rep; } else { logger.error("Bad request: Invalid application id passed to endpoint"); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid application id passed to endpoint"); } }  }
UserPrefsFormUIResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { if (moduleId != null && moduleId > 0 && gadgetDefUrl != null) { StringBuilder sb = new StringBuilder(); try { Map<String, GeneralGadgetDefinition> gadgetDefs = new HashMap<String, GeneralGadgetDefinition>(); GadgetDefinition targetGadgetDef = gadgetMapper.findById(moduleId).getGadgetDefinition(); gadgetDefs.put(gadgetDefUrl, targetGadgetDef); List<GadgetMetaDataDTO> gadgetMetaData = gadgetMetaFetcher.getGadgetsMetaData(gadgetDefs); for (GadgetMetaDataDTO currentGMeta : gadgetMetaData) { logger.debug("Retrieved Metadata for Gadget" + targetGadgetDef.getId() + " Author: " + currentGMeta.getAuthor() + " UserPrefsSize: " + currentGMeta.getUserPrefs().size()); buildUserPreferencesUI(currentGMeta, sb); } } catch (Exception ex) { logger.error("Error occurred retrieving User Preferences script", ex); sb.append("var htmlString_" + moduleId + "='';"); sb.append("htmlString_" + moduleId + " += '<div class=\"gadget-preferences\">" + USER_PREFS_ERROR_MESSAGE + "</div>';"); sb.append("gadget_callback_" + moduleId + "(htmlString_" + moduleId + ");"); } logger.debug("Returning the edit settings script: " + sb.toString()); Representation rep = new StringRepresentation(sb.toString(), MediaType.APPLICATION_JAVASCRIPT); rep.setExpirationDate(new Date()); return rep; } else { logger.error("Bad request: Invalid application id passed to endpoint"); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid application id passed to endpoint"); } }  void setGadgetMapper(final GadgetMapper inGadgetMapper); void setGadgetMetaDataFetcher(final GadgetMetaDataFetcher inGadgetMetaFetcher); @Override Representation represent(final Variant variant); }
UserPrefsFormUIResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { if (moduleId != null && moduleId > 0 && gadgetDefUrl != null) { StringBuilder sb = new StringBuilder(); try { Map<String, GeneralGadgetDefinition> gadgetDefs = new HashMap<String, GeneralGadgetDefinition>(); GadgetDefinition targetGadgetDef = gadgetMapper.findById(moduleId).getGadgetDefinition(); gadgetDefs.put(gadgetDefUrl, targetGadgetDef); List<GadgetMetaDataDTO> gadgetMetaData = gadgetMetaFetcher.getGadgetsMetaData(gadgetDefs); for (GadgetMetaDataDTO currentGMeta : gadgetMetaData) { logger.debug("Retrieved Metadata for Gadget" + targetGadgetDef.getId() + " Author: " + currentGMeta.getAuthor() + " UserPrefsSize: " + currentGMeta.getUserPrefs().size()); buildUserPreferencesUI(currentGMeta, sb); } } catch (Exception ex) { logger.error("Error occurred retrieving User Preferences script", ex); sb.append("var htmlString_" + moduleId + "='';"); sb.append("htmlString_" + moduleId + " += '<div class=\"gadget-preferences\">" + USER_PREFS_ERROR_MESSAGE + "</div>';"); sb.append("gadget_callback_" + moduleId + "(htmlString_" + moduleId + ");"); } logger.debug("Returning the edit settings script: " + sb.toString()); Representation rep = new StringRepresentation(sb.toString(), MediaType.APPLICATION_JAVASCRIPT); rep.setExpirationDate(new Date()); return rep; } else { logger.error("Bad request: Invalid application id passed to endpoint"); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid application id passed to endpoint"); } }  void setGadgetMapper(final GadgetMapper inGadgetMapper); void setGadgetMetaDataFetcher(final GadgetMetaDataFetcher inGadgetMetaFetcher); @Override Representation represent(final Variant variant);  }