PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/org/andya/confluence/plugins/metadata/MetadataTotalMacro.java

https://bitbucket.org/jwalton/metadata-confluence-plugin
Java | 66 lines | 27 code | 7 blank | 32 comment | 1 complexity | 16578ccc45c68e7f9ec9a295947cbc30 MD5 | raw file
  1. /*
  2. * Copyright (c) 2006, 2007 Andy Armstrong, Kelsey Grant and other contributors.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * * The names of contributors may not
  14. * be used to endorse or promote products derived from this software without
  15. * specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  21. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. package org.andya.confluence.plugins.metadata;
  29. import com.atlassian.renderer.v2.macro.MacroException;
  30. import com.atlassian.renderer.RenderContext;
  31. import java.util.*;
  32. import org.andya.confluence.plugins.metadata.model.MetadataContent;
  33. import org.andya.confluence.utils.MacroUtils;
  34. /**
  35. * This macro totals up values of metadata across all pages with matching labels.
  36. * Note that this class has been replaced by MetadataCalculateMacro.
  37. * @deprecated
  38. */
  39. public class MetadataTotalMacro extends MetadataUsingMacro {
  40. public MetadataTotalMacro() {
  41. super("metadata-total");
  42. }
  43. public boolean isInline() {
  44. return true;
  45. }
  46. @SuppressWarnings("unchecked")
  47. public String execute(Map parameters, String body, RenderContext renderContext) throws MacroException {
  48. try {
  49. String valueName = MacroUtils.getStringParameter(parameters, "0", true);
  50. String metadataName = MacroUtils.getStringParameter(parameters, METADATA_PARAMETER, null);
  51. String metadataValue = metadataName != null ? MacroUtils.getStringParameter(parameters, metadataName, true) : null;
  52. List<MetadataContent> contents = getMatchingPages(parameters, getContentService(), renderContext, false);
  53. List<Number> numbers = MetadataUtils.getMetadataNumbers(contents, valueName, metadataName, metadataValue);
  54. return renderCalculation("sum", numbers);
  55. } catch (Exception e) {
  56. return showRenderedExceptionString(parameters, e);
  57. }
  58. }
  59. }