Statistics
| Branch: | Tag: | Revision:

root / src / main / scala / com / normation / cfclerk / services / TechniqueReader.scala @ 297687b8

History | View | Annotate | Download (4.1 kB)

1
/*
2
*************************************************************************************
3
* Copyright 2011 Normation SAS
4
*************************************************************************************
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Affero General Public License as
8
* published by the Free Software Foundation, either version 3 of the
9
* License, or (at your option) any later version.
10
*
11
* In accordance with the terms of section 7 (7. Additional Terms.) of
12
* the GNU Affero GPL v3, the copyright holders add the following
13
* Additional permissions:
14
* Notwithstanding to the terms of section 5 (5. Conveying Modified Source
15
* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU Affero GPL v3
16
* licence, when you create a Related Module, this Related Module is
17
* not considered as a part of the work and may be distributed under the
18
* license agreement of your choice.
19
* A "Related Module" means a set of sources files including their
20
* documentation that, without modification of the Source Code, enables
21
* supplementary functions or services in addition to those offered by
22
* the Software.
23
*
24
* This program is distributed in the hope that it will be useful,
25
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
* GNU Affero General Public License for more details.
28
*
29
* You should have received a copy of the GNU Affero General Public License
30
* along with this program. If not, see <http://www.gnu.org/licenses/agpl.html>.
31
*
32
*************************************************************************************
33
*/
34

    
35
package com.normation.cfclerk.services
36

    
37
import com.normation.cfclerk.domain._
38
import java.io.InputStream
39
import scala.collection.immutable.SortedMap
40
import scala.collection.mutable.{ Map => MutMap }
41
import com.normation.utils.HashcodeCaching
42

    
43

    
44
case class TechniquesInfo(
45
    rootCategory: RootTechniqueCategory
46
    //the TechniqueCategoryId is a path from the point of view of a tree
47
  , techniquesCategory: Map[TechniqueId, TechniqueCategoryId]
48
  , techniques: Map[TechniqueName, SortedMap[TechniqueVersion, Technique]]
49
    //head of categories is the root category
50
  , subCategories: Map[SubTechniqueCategoryId, TechniqueCategory]
51
) extends HashcodeCaching 
52

    
53
//a mutable version of TechniquesInfo, for internal use only !
54
private[services] class InternalTechniquesInfo(
55
    var rootCategory: Option[RootTechniqueCategory] = None
56
  , val techniquesCategory: MutMap[TechniqueId, TechniqueCategoryId] = MutMap()
57
  , val techniques: MutMap[TechniqueName, MutMap[TechniqueVersion, Technique]] = MutMap()
58
  , val subCategories: MutMap[SubTechniqueCategoryId, SubTechniqueCategory] = MutMap()
59
)
60

    
61
/**
62
 * This class is in charge to maintain a map of
63
 * available policy package.
64
 * A package is composed of a policy identified by its name
65
 * and all the relevant information like its templates.
66
 *
67
 */
68
trait TechniqueReader {
69

    
70
  /**
71
   * read the policies from the source directory.
72
   * return the policy package and the the full path to its
73
   * root directory for the "current" revision of the
74
   * reference library. "current" pointer update is 
75
   * implementation dependent, some implementation doesn't
76
   * have any notion of version, other using getModifiedTechniques
77
   * for updating the available "next" state. 
78
   */
79
  def readTechniques(): TechniquesInfo
80

    
81
  /**
82
   * Read the content of a template, if the template is known by that
83
   * TechniqueReader.
84
   * If the template exists, then a Some(input stream), open at the
85
   * beginning of the template is given to the caller. 
86
   * If not, a None is given. 
87
   * The implementation must take care of correct closing of the input
88
   * stream and any I/O exception. 
89
   */
90
  def getTemplateContent[T](templateName: Cf3PromisesFileTemplateId)(useIt : Option[InputStream] => T) : T
91
 
92
  /**
93
   * An indicator that the underlying policy template library changed and that the content 
94
   * should be read again.
95
   * If the sequence is empty, then nothing changed. Else, the list of Technique with 
96
   * *any* change will be given
97
   */
98
  def getModifiedTechniques : Seq[TechniqueId]
99
}
100