-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73dd77f
commit bfc0ebe
Showing
13 changed files
with
801 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/Bundle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.labs64.netlicensing.domain.entity; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
import com.labs64.netlicensing.domain.vo.Currency; | ||
|
||
public interface Bundle extends BaseEntity { | ||
void setName(String name); | ||
|
||
String getName(); | ||
|
||
void setPrice(BigDecimal price); | ||
|
||
BigDecimal getPrice(); | ||
|
||
void setCurrency(Currency currency); | ||
|
||
Currency getCurrency(); | ||
|
||
void setDescription(String description); | ||
|
||
String getDescription(); | ||
|
||
void setLicenseTemplatesNumbers(List<String> licenseTemplatesNumbers); | ||
|
||
List<String> getLicenseTemplatesNumbers(); | ||
|
||
void addLicenseTemplateNumber(String licenseTemplateNumber); | ||
|
||
void removeLicenseTemplateNumber(String licenseTemplateNumber); | ||
} |
120 changes: 120 additions & 0 deletions
120
NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/BundleImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.labs64.netlicensing.domain.entity.impl; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.ws.rs.core.MultivaluedMap; | ||
|
||
import com.labs64.netlicensing.domain.Constants; | ||
import com.labs64.netlicensing.domain.entity.Bundle; | ||
import com.labs64.netlicensing.domain.vo.Currency; | ||
|
||
public class BundleImpl extends BaseEntityImpl implements Bundle { | ||
private String name; | ||
|
||
private String description; | ||
|
||
private BigDecimal price; | ||
|
||
private Currency currency; | ||
|
||
private List<String> licenseTemplatesNumbers; | ||
|
||
@Override | ||
public void setName(final String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public void setPrice(final BigDecimal price) { | ||
this.price = price; | ||
} | ||
|
||
@Override | ||
public BigDecimal getPrice() { | ||
return price; | ||
} | ||
|
||
@Override | ||
public void setCurrency(final Currency currency) { | ||
this.currency = currency; | ||
} | ||
|
||
@Override | ||
public Currency getCurrency() { | ||
return currency; | ||
} | ||
|
||
@Override | ||
public void setDescription(final String description) { | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Override | ||
public void setLicenseTemplatesNumbers(final List<String> licenseTemplatesNumbers) { | ||
this.licenseTemplatesNumbers = licenseTemplatesNumbers; | ||
} | ||
|
||
@Override | ||
public List<String> getLicenseTemplatesNumbers() { | ||
return licenseTemplatesNumbers; | ||
} | ||
|
||
@Override | ||
public void addLicenseTemplateNumber(final String licenseTemplateNumber) { | ||
if (getLicenseTemplatesNumbers() == null) { | ||
this.licenseTemplatesNumbers = new ArrayList<>(); | ||
} | ||
|
||
this.licenseTemplatesNumbers.add(licenseTemplateNumber); | ||
} | ||
|
||
@Override | ||
public void removeLicenseTemplateNumber(final String licenseTemplateNumber) { | ||
if (getLicenseTemplatesNumbers() == null) { | ||
return; | ||
} | ||
|
||
getLicenseTemplatesNumbers().remove(licenseTemplateNumber); | ||
} | ||
|
||
public static List<String> getReservedProps() { | ||
final List<String> reserved = BaseEntityImpl.getReservedProps(); | ||
reserved.add(Constants.NAME); | ||
reserved.add(Constants.Bundle.DESCRIPTION); | ||
reserved.add(Constants.PRICE); | ||
reserved.add(Constants.CURRENCY); | ||
reserved.add(Constants.Bundle.LICENSE_TEMPLATES_NUMBERS); | ||
return reserved; | ||
} | ||
|
||
@Override | ||
protected MultivaluedMap<String, Object> asPropertiesMap() { | ||
final MultivaluedMap<String, Object> map = super.asPropertiesMap(); | ||
map.add(Constants.NAME, getName()); | ||
|
||
if (getDescription() != null) { | ||
map.add(Constants.Bundle.DESCRIPTION, getDescription()); | ||
} | ||
|
||
map.add(Constants.PRICE, getPrice()); | ||
map.add(Constants.CURRENCY, getCurrency()); | ||
|
||
if (getLicenseTemplatesNumbers() != null) { | ||
map.add(Constants.Bundle.LICENSE_TEMPLATES_NUMBERS, String.join(",", getLicenseTemplatesNumbers())); | ||
} | ||
|
||
return map; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...censingClient/src/main/java/com/labs64/netlicensing/domain/vo/BundleObtainParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.labs64.netlicensing.domain.vo; | ||
|
||
public class BundleObtainParameters { | ||
|
||
private String licenseeNumber; | ||
|
||
public String getLicenseeNumber() { | ||
return licenseeNumber; | ||
} | ||
|
||
public void setLicenseeNumber(final String licenseeNumber) { | ||
this.licenseeNumber = licenseeNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...gClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToBundleConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.labs64.netlicensing.schema.converter; | ||
|
||
import java.util.Arrays; | ||
|
||
import com.labs64.netlicensing.domain.Constants; | ||
import com.labs64.netlicensing.domain.entity.Bundle; | ||
import com.labs64.netlicensing.domain.entity.impl.BundleImpl; | ||
import com.labs64.netlicensing.domain.entity.impl.LicenseTemplateImpl; | ||
import com.labs64.netlicensing.domain.vo.Currency; | ||
import com.labs64.netlicensing.domain.vo.Money; | ||
import com.labs64.netlicensing.exception.ConversionException; | ||
import com.labs64.netlicensing.schema.SchemaFunction; | ||
import com.labs64.netlicensing.schema.context.Item; | ||
import com.labs64.netlicensing.schema.context.Property; | ||
|
||
/** | ||
* Convert {@link Item} entity into {@link Bundle} object. | ||
*/ | ||
public class ItemToBundleConverter extends ItemToEntityBaseConverter<Bundle> { | ||
|
||
@Override | ||
public Bundle convert(final Item source) throws ConversionException { | ||
final Bundle target = super.convert(source); | ||
|
||
target.setName(SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue()); | ||
target.setDescription(SchemaFunction.propertyByName(source.getProperty(), Constants.Bundle.DESCRIPTION).getValue()); | ||
if (SchemaFunction.propertyByName(source.getProperty(), Constants.PRICE).getValue() != null) { | ||
final Money price = convertPrice(source.getProperty(), Constants.PRICE); | ||
target.setPrice(price.getAmount()); | ||
target.setCurrency(Currency.valueOf(price.getCurrencyCode())); | ||
} | ||
|
||
final String licenseTemplatesNumbers = SchemaFunction.propertyByName(source.getProperty(), Constants.Bundle.LICENSE_TEMPLATES_NUMBERS).getValue(); | ||
|
||
if (licenseTemplatesNumbers != null) { | ||
target.setLicenseTemplatesNumbers(Arrays.asList(licenseTemplatesNumbers.split(","))); | ||
} | ||
|
||
// Custom properties | ||
for (final Property property : source.getProperty()) { | ||
if (!LicenseTemplateImpl.getReservedProps().contains(property.getName())) { | ||
target.getProperties().put(property.getName(), property.getValue()); | ||
} | ||
} | ||
|
||
return target; | ||
} | ||
|
||
@Override | ||
public Bundle newTarget() { | ||
return new BundleImpl(); | ||
} | ||
|
||
} |
Oops, something went wrong.