Skip to content

Commit

Permalink
- move IdGenerator
Browse files Browse the repository at this point in the history
- additional elements added to the ExtendedSwidProcessor
  • Loading branch information
r-brown committed Jan 1, 2015
1 parent 11a2522 commit f0926a0
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -36,7 +36,7 @@ To generate SoftWare IDentification (SWID) Tag ([gist](https://gist.github.com/r
SwidProcessor processor = new DefaultSwidProcessor();
((DefaultSwidProcessor) processor).setEntitlementRequiredIndicator(true)
.setProductTitle("NetLicensing")
.setProductVersion("2.2.0", 2, 2, 0, 0)
.setProductVersion("2.1.0", 2, 1, 0, 0)
.setSoftwareCreator("Labs64", "regid.2010-04.com.labs64")
.setSoftwareLicensor("Labs64", "regid.2010-04.com.labs64")
.setSoftwareId("NLIC", "regid.2010-04.com.labs64")
Expand All @@ -61,10 +61,10 @@ System.out.println(out);
<entitlement_required_indicator>true</entitlement_required_indicator>
<product_title>NetLicensing</product_title>
<product_version>
<name>2.2.0</name>
<name>2.1.0</name>
<numeric>
<major>2</major>
<minor>2</minor>
<minor>1</minor>
<build>0</build>
<review>0</review>
</numeric>
Expand Down
Expand Up @@ -22,6 +22,8 @@
import org.iso.standards.iso._19770.__2._2009.schema.UInt;

import com.labs64.utils.swid.exception.SwidException;
import com.labs64.utils.swid.support.IdGenerator;
import com.labs64.utils.swid.support.NullIdGenerator;

/**
* Default SWID tag processor creates SWID tag with pre-defined mandatory elements.
Expand Down
Expand Up @@ -12,14 +12,20 @@
*/
package com.labs64.utils.swid.processor;

import java.math.BigInteger;
import java.util.Date;

import javax.xml.bind.JAXBElement;

import org.iso.standards.iso._19770.__2._2009.schema.AbstractComplexType;
import org.iso.standards.iso._19770.__2._2009.schema.CategoryComplexType;
import org.iso.standards.iso._19770.__2._2009.schema.DateTime;
import org.iso.standards.iso._19770.__2._2009.schema.ExtendedInformationComplexType;
import org.iso.standards.iso._19770.__2._2009.schema.KeywordsComplexType;
import org.iso.standards.iso._19770.__2._2009.schema.SoftwareIdentificationTagComplexType;
import org.iso.standards.iso._19770.__2._2009.schema.SupportedLanguagesComplexType;
import org.iso.standards.iso._19770.__2._2009.schema.Token;
import org.iso.standards.iso._19770.__2._2009.schema.UnspscIdType;

import com.labs64.utils.swid.support.JAXBUtils;

Expand Down Expand Up @@ -113,6 +119,40 @@ public ExtendedSwidProcessor setProductId(final String... productIdList) {
return this;
}

/**
* Defines product category (tag: product_category).
*
* @see <a href="http://en.wikipedia.org/wiki/UNSPSC">United Nations Standard Products and Services Code
* (UNSPSC)</a> for guidance.
*
* @param unspscVer
* UNSPSC version
* @param segmentTitle
* segment title
* @param familyTitle
* family title
* @param classTitle
* class title
* @param commodityTitle
* commodity title
* @param code
* UNSPSC code
* @return a reference to this object.
*/
public ExtendedSwidProcessor setProductCategory(final String unspscVer, final String segmentTitle,
final String familyTitle, final String classTitle, final String commodityTitle, final BigInteger code) {
final CategoryComplexType cct = new CategoryComplexType(
new Token(unspscVer, idGenerator.nextId()),
new Token(segmentTitle, idGenerator.nextId()),
new Token(familyTitle, idGenerator.nextId()),
new Token(classTitle, idGenerator.nextId()),
new Token(commodityTitle, idGenerator.nextId()),
new UnspscIdType(code, idGenerator.nextId()),
idGenerator.nextId());
swidTag.setProductCategory(cct);
return this;
}

/**
* Defines product release date (tag: release_date).
*
Expand Down Expand Up @@ -180,6 +220,24 @@ public ExtendedSwidProcessor setSupportedLanguages(final String... supportedLang
return this;
}

/**
* Defines product extended information (tag: extended_information).
*
* @param extendedInformationList
* product extended information
* @return a reference to this object.
*/
public ExtendedSwidProcessor setExtendedInformation(final JAXBElement<Object>... extendedInformationList) {
ExtendedInformationComplexType eict = new ExtendedInformationComplexType();
if (extendedInformationList.length > 0) {
for (JAXBElement<Object> extendedInformation : extendedInformationList) {
eict.getAny().add(extendedInformation);
}
}
swidTag.getExtendedInformation().add(eict);
return this;
}

/**
* Validate whether processor configuration is valid.
*
Expand Down
Expand Up @@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.labs64.utils.swid.processor;
package com.labs64.utils.swid.support;

/**
* Interface for generate of SWID Tags elements identifiers.
Expand Down
@@ -1,4 +1,4 @@
package com.labs64.utils.swid.processor;
package com.labs64.utils.swid.support;

/**
* This generator always returns <code>null</code> as element identifier.
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/labs64/utils/swid/SwidBuilderTest.java
Expand Up @@ -83,7 +83,7 @@ public void testBuilderUseCase() {
SwidProcessor processor = new DefaultSwidProcessor();
((DefaultSwidProcessor) processor).setEntitlementRequiredIndicator(true)
.setProductTitle("NetLicensing")
.setProductVersion("2.2.0", 2, 2, 0, 0)
.setProductVersion("2.1.0", 2, 1, 0, 0)
.setSoftwareCreator("Labs64", regid)
.setSoftwareLicensor("Labs64", regid)
.setSoftwareId("NLIC", regid)
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/labs64/utils/swid/io/SwidWriterTest.java
Expand Up @@ -50,7 +50,7 @@ public void testWriteOutputStream() {
@Test
public void testWriteFile() {
final String regid = SwidUtils.generateRegId("2010-04", "com.labs64");
final String tagFile = SwidUtils.generateSwidFileName(regid, "NetLicensing", "220");
final String tagFile = SwidUtils.generateSwidFileName(regid, "NetLicensing", "210");
File destination = new File("target/" + tagFile);
underTest.write(new SoftwareIdentificationTagComplexType(), destination);
assertTrue(destination.length() > 0);
Expand Down
Expand Up @@ -59,7 +59,7 @@ public void testProcessorFull() {
final String regid = SwidUtils.generateRegId("2010-04", "com.labs64");
underTest.setEntitlementRequiredIndicator(true)
.setProductTitle("NetLicensing")
.setProductVersion("2.2.0", 2, 2, 0, 0)
.setProductVersion("2.1.0", 2, 1, 0, 0)
.setSoftwareCreator("Labs64", regid)
.setSoftwareLicensor("Labs64", regid)
.setSoftwareId("NLIC", regid)
Expand Down
Expand Up @@ -12,8 +12,12 @@
*/
package com.labs64.utils.swid.processor;

import java.math.BigInteger;
import java.util.Date;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

import org.iso.standards.iso._19770.__2._2009.schema.ObjectFactory;
import org.iso.standards.iso._19770.__2._2009.schema.SoftwareIdentificationTagComplexType;
import org.junit.Before;
Expand Down Expand Up @@ -62,27 +66,35 @@ public void testProcessorFull() {
// set mandatory properties (see also com.labs64.utils.swid.processor.DefaultSwidProcessor)
underTest.setEntitlementRequiredIndicator(true)
.setProductTitle("NetLicensing")
.setProductVersion("2.2.0", 2, 2, 0, 0)
.setProductVersion("2.1.0", 2, 1, 0, 0)
.setSoftwareCreator("Labs64", regid)
.setSoftwareLicensor("Labs64", regid)
.setSoftwareId("NLIC", regid)
.setTagCreator("Labs64", regid);
// set extended optional properties
underTest.setKeywords("TryAndBuy", "Subscription", "Rental", "Floating", "etc.")
underTest
.setKeywords("TryAndBuy", "Subscription", "Rental", "Floating", "etc.")
.setAbstract("Innovative License Management Solution", "Application Licensing for Professionals")
.setDataSource("https://netlicensing.labs64.com/")
.setProductFamily("Online License Management")
.setProductId("NLIC", "LMB")
.setProductCategory("16.0901", "81", "11", "20", "01", BigInteger.valueOf(81112001))
.setReleaseDate(new Date())
.setReleaseId("2.2.0-Final")
.setReleaseId("2.1.0-Final")
.setSerialNumber("SN-0123456789")
.setSku("SKU-0123456789")
.setSupportedLanguages("en", "de", "ru");
.setSupportedLanguages("en", "de", "ru")
.setExtendedInformation(
new JAXBElement(
new QName("http://netlicensing.labs64.com/schema/context/netlicensing-context-2.1.xsd",
"netlicensing"),
String.class,
null,
"NetLicensing Schema"));

SoftwareIdentificationTagComplexType swidElement = underTest.process();
assertNotNull(swidElement);
final String out = JAXBUtils.writeObjectToString(objectFactory.createSoftwareIdentificationTag(swidElement));
System.out.println(out);
}

}
Expand Up @@ -55,15 +55,15 @@ public void testGenerateRegIdSuffix() {
@Test
public void testGenerateSwidFileName() {
final String regid = SwidUtils.generateRegId("2010-04", "com.labs64");
assertEquals("regid.2010-04.com.labs64_NetLicensing-220.swidtag",
SwidUtils.generateSwidFileName(regid, "NetLicensing", "220"));
assertEquals("regid.2010-04.com.labs64_NetLicensing-210.swidtag",
SwidUtils.generateSwidFileName(regid, "NetLicensing", "210"));
}

@Test
public void testGenerateSwidFileNameExtension() {
final String regid = SwidUtils.generateRegId("2010-04", "com.labs64");
assertEquals("regid.2010-04.com.labs64_NetLicensing-220.swidtag",
SwidUtils.generateSwidFileName(regid, "NetLicensing", "220", SwidUtils.SWIDTAG_FILE_EXTENSION));
assertEquals("regid.2010-04.com.labs64_NetLicensing-210.swidtag",
SwidUtils.generateSwidFileName(regid, "NetLicensing", "210", SwidUtils.SWIDTAG_FILE_EXTENSION));
}

@Test
Expand Down

0 comments on commit f0926a0

Please sign in to comment.