Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
5495-app - allow material dispo to run within app
- MetasfreshBeanNameGenerator: change it to use FQCN for *all* metasfresh components
- add profile annotation to classes in material-dispo-service module (most already had it!)
- add material-dispo-service module as dependency to de.metas.fresh
- add sysconfig to have metasfresh-app a.k.a. serverRoot run with embedded material-dispo service
#5495
  • Loading branch information
metas-ts committed Sep 6, 2019
1 parent 151a47f commit 6682177
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 46 deletions.
@@ -1,9 +1,8 @@
package de.metas;

import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.core.type.AnnotationMetadata;
import lombok.NonNull;

/*
* #%L
Expand All @@ -15,12 +14,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
Expand All @@ -29,54 +28,26 @@

public class MetasfreshBeanNameGenerator extends AnnotationBeanNameGenerator
{
private static final String CLASSNAME_Interceptor = org.adempiere.ad.modelvalidator.annotations.Interceptor.class.getName();
private static final String CLASSNAME_Callout = org.adempiere.ad.callout.annotations.Callout.class.getName();

@Override
protected String buildDefaultBeanName(final BeanDefinition definition)
protected String buildDefaultBeanName(@NonNull final BeanDefinition definition)
{
if (isInterceptor(definition))
{
// Because we have more than one model Interceptor with the same class name but in different packages,
// it's better to name the bean after it's FQ name instead of just simple class name
return extractFullyQualifiedBeanClassName(definition);
}
else if (isCallout(definition))
if (isMetasfreshPackage(definition))
{
// Because we have more than one Callout with the same class name but in different packages,
// it's better to name the bean after it's FQ name instead of just simple class name
return extractFullyQualifiedBeanClassName(definition);
}
else
{
// Fallback to standard way of naming beans
// i.e. simple class name, first letter lower case
return super.buildDefaultBeanName(definition);
}
}

private static boolean isInterceptor(final BeanDefinition definition)
{
return hasAnnotation(definition, CLASSNAME_Interceptor);
// Fallback to standard way of naming beans
// i.e. simple class name, first letter lower case
return super.buildDefaultBeanName(definition);
}

private static boolean isCallout(final BeanDefinition definition)
private boolean isMetasfreshPackage(@NonNull final BeanDefinition definition)
{
return hasAnnotation(definition, CLASSNAME_Callout);
}
final String beanClassName = definition.getBeanClassName();

private static boolean hasAnnotation(final BeanDefinition definition, final String annotationClassname)
{
if (definition instanceof AnnotatedBeanDefinition)
{
final AnnotatedBeanDefinition annotatedDef = (AnnotatedBeanDefinition)definition;
final AnnotationMetadata amd = annotatedDef.getMetadata();
return amd.hasAnnotation(annotationClassname);
}
else
{
return false;
}
return beanClassName.startsWith("de.metas")
|| beanClassName.startsWith("org.adempiere")
|| beanClassName.startsWith("org.eevolution");
}

private static String extractFullyQualifiedBeanClassName(final BeanDefinition definition)
Expand Down
@@ -0,0 +1,11 @@
-- 2019-09-06T13:28:32.795Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_SysConfig (AD_Client_ID,AD_Org_ID,AD_SysConfig_ID,ConfigurationLevel,Created,CreatedBy,Description,EntityType,IsActive,Name,Updated,UpdatedBy,Value) VALUES (0,0,541286,'S',TO_TIMESTAMP('2019-09-06 15:28:32','YYYY-MM-DD HH24:MI:SS'),100,'Activate this to run the material-dispo service within the metasfresh-app service.
Alternatively, you can run material-dispo as standalone service (we have a docker image!), or depending on your requirements you might decide not to run it at all.
','de.metas.material.dispo','Y','de.metas.spring.profiles.active_material-dispo',TO_TIMESTAMP('2019-09-06 15:28:32','YYYY-MM-DD HH24:MI:SS'),100,'material-dispo')
;

-- 2019-09-06T13:28:40.156Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE AD_SysConfig SET IsActive='Y',Updated=TO_TIMESTAMP('2019-09-06 15:28:40','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_SysConfig_ID=541286
;
12 changes: 11 additions & 1 deletion de.metas.fresh/de.metas.fresh.base/pom.xml
Expand Up @@ -185,7 +185,7 @@
<artifactId>de.metas.payment.sepa</artifactId>
<version>${metasfresh.version}</version>
</dependency>

<dependency>
<groupId>de.metas.payment.paypal</groupId>
<artifactId>de.metas.payment.paypal</artifactId>
Expand Down Expand Up @@ -299,6 +299,16 @@
<version>${metasfresh.version}</version>
</dependency>

<!-- include material-dispo;
This component will only be active within metasfresh-app (a.k.a. serverRoot)
if the spring profile "material-dispo" is active. One way of activating that profile is to
find the existing AD_SysConfig with Name="de.metas.spring.profiles.active_material-dispo" and set is to IsActive='Y' -->
<dependency>
<groupId>de.metas.material</groupId>
<artifactId>metasfresh-material-dispo-service</artifactId>
<version>${metasfresh.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Expand Up @@ -5,11 +5,13 @@

import org.adempiere.exceptions.AdempiereException;
import org.slf4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;

import de.metas.Profiles;
import de.metas.logging.LogManager;
import de.metas.material.dispo.commons.candidate.Candidate;
import de.metas.material.dispo.commons.candidate.CandidateType;
Expand Down Expand Up @@ -38,6 +40,7 @@
* #L%
*/
@Service
@Profile(Profiles.PROFILE_MaterialDispo)
public class CandidateChangeService
{
private static final Logger logger = LogManager.getLogger(CandidateChangeService.class);
Expand Down
Expand Up @@ -8,8 +8,10 @@
import java.util.List;

import org.compiere.util.TimeUtil;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import de.metas.Profiles;
import de.metas.material.dispo.commons.candidate.Candidate;
import de.metas.material.dispo.commons.candidate.CandidateId;
import de.metas.material.dispo.commons.candidate.CandidateType;
Expand Down Expand Up @@ -52,6 +54,7 @@
*/

@Service
@Profile(Profiles.PROFILE_MaterialDispo)
public class StockCandidateService
{
private final CandidateRepositoryRetrieval candidateRepositoryRetrieval;
Expand Down
Expand Up @@ -6,11 +6,13 @@
import java.util.Collection;
import java.util.Optional;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import de.metas.Profiles;
import de.metas.material.dispo.commons.candidate.Candidate;
import de.metas.material.dispo.commons.candidate.CandidateId;
import de.metas.material.dispo.commons.candidate.CandidateType;
Expand Down Expand Up @@ -50,6 +52,7 @@
*/

@Service
@Profile(Profiles.PROFILE_MaterialDispo)
public class DemandCandiateHandler implements CandidateHandler
{
private final CandidateRepositoryRetrieval candidateRepository;
Expand Down
Expand Up @@ -3,11 +3,13 @@
import java.math.BigDecimal;
import java.util.Collection;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import de.metas.Profiles;
import de.metas.material.dispo.commons.candidate.Candidate;
import de.metas.material.dispo.commons.candidate.CandidateType;
import de.metas.material.dispo.commons.repository.CandidateRepositoryRetrieval;
Expand Down Expand Up @@ -48,6 +50,7 @@
*
*/
@Service
@Profile(Profiles.PROFILE_MaterialDispo)
public class StockUpCandiateHandler implements CandidateHandler
{
@NonNull
Expand Down
Expand Up @@ -4,11 +4,13 @@

import java.util.Collection;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import de.metas.Profiles;
import de.metas.material.dispo.commons.candidate.Candidate;
import de.metas.material.dispo.commons.candidate.CandidateType;
import de.metas.material.dispo.commons.repository.CandidateRepositoryWriteService;
Expand Down Expand Up @@ -40,6 +42,7 @@
* #L%
*/
@Service
@Profile(Profiles.PROFILE_MaterialDispo)
public class SupplyCandidateHandler implements CandidateHandler
{
private final CandidateRepositoryWriteService candidateRepositoryWriteService;
Expand Down
@@ -1,8 +1,10 @@
package de.metas.material.dispo.service.event;

import org.adempiere.warehouse.WarehouseId;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import de.metas.Profiles;
import de.metas.material.dispo.commons.candidate.Candidate;
import de.metas.material.dispo.commons.candidate.CandidateType;
import de.metas.material.dispo.commons.candidate.businesscase.DemandDetail;
Expand Down Expand Up @@ -44,6 +46,7 @@
*
*/
@Service
@Profile(Profiles.PROFILE_MaterialDispo)
public class SupplyProposalEvaluator
{
/**
Expand Down
Expand Up @@ -36,7 +36,7 @@
*/

@Interceptor(I_C_UOM_Conversion.class)
@Component("de.metas.inoutcandidate.modelvalidator.C_UOM_Conversion")
@Component
public class C_UOM_Conversion
{
private static final String SYSCONFIG_SHIPMENT_SCHEDULE_CATCH_UOM_ID_UPDATE_DELAY_MS = "de.metas.inoutcandidate.M_ShipmentSchedule.CatchUOM_ID_update_delay_ms";
Expand Down
Expand Up @@ -34,7 +34,7 @@
*/

@Interceptor(I_C_InvoiceCandidate_InOutLine.class)
@Component("de.metas.invoicecandidate.modelvalidator.C_InvoiceCandidate_InOutLine")
@Component
public class C_InvoiceCandidate_InOutLine
{
private final InvoiceCandidateRepository invoiceCandidateRepository;
Expand Down
Expand Up @@ -42,7 +42,7 @@
import lombok.NonNull;

@Interceptor(I_M_InOutLine.class)
@Component("de.metas.invoicecandidate.modelvalidator.M_InOutLine")
@Component
public class M_InOutLine
{
private final InvoiceCandidateRecordService invoiceCandidateRecordService;
Expand Down

0 comments on commit 6682177

Please sign in to comment.