Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5755-app - Create endpoint to directly insert invoice candidates
* starting to work on lookup/retrieval-code for masterdata (BPartner) and ICs #5755
- Loading branch information
Showing
4 changed files
with
192 additions
and
56 deletions.
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
104 changes: 104 additions & 0 deletions
104
...as.business.rest-api-impl/src/main/java/de/metas/rest_api/utils/BPartnerQueryService.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,104 @@ | ||
package de.metas.rest_api.utils; | ||
|
||
import static de.metas.util.Check.isEmpty; | ||
|
||
import java.util.Collection; | ||
|
||
import org.compiere.util.Env; | ||
import org.springframework.stereotype.Service; | ||
|
||
import de.metas.bpartner.BPartnerId; | ||
import de.metas.bpartner.GLN; | ||
import de.metas.bpartner.service.BPartnerQuery; | ||
import de.metas.organization.OrgId; | ||
import de.metas.rest_api.JsonExternalId; | ||
import de.metas.rest_api.MetasfreshId; | ||
import de.metas.rest_api.bpartner.impl.bpartnercomposite.BPartnerCompositeLookupKey; | ||
import lombok.NonNull; | ||
|
||
/* | ||
* #%L | ||
* de.metas.business.rest-api-impl | ||
* %% | ||
* Copyright (C) 2019 metas GmbH | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* 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>. | ||
* #L% | ||
*/ | ||
|
||
@Service | ||
public class BPartnerQueryService | ||
{ | ||
public BPartnerQuery createQuery(@NonNull final Collection<BPartnerCompositeLookupKey> queryLookupKeys) | ||
{ | ||
final OrgId onlyOrgId = Env.getOrgId(); // FIXME avoid using Env.getOrgId(); | ||
return createBPartnerQuery(queryLookupKeys, onlyOrgId); | ||
} | ||
|
||
public BPartnerQuery createQueryFailIfNotExists(@NonNull final BPartnerCompositeLookupKey queryLookupKey) | ||
{ | ||
final OrgId onlyOrgId = Env.getOrgId(); // FIXME avoid using Env.getOrgId(); | ||
|
||
final BPartnerQuery.BPartnerQueryBuilder queryBuilder = BPartnerQuery.builder() | ||
.onlyOrgId(onlyOrgId) | ||
.failIfNotExists(true); | ||
addKeyToQueryBuilder(queryLookupKey, queryBuilder); | ||
|
||
return queryBuilder.build(); | ||
} | ||
|
||
private static BPartnerQuery createBPartnerQuery( | ||
@NonNull final Collection<BPartnerCompositeLookupKey> bpartnerLookupKeys, | ||
@NonNull final OrgId onlyOrgId) | ||
{ | ||
final BPartnerQuery.BPartnerQueryBuilder query = BPartnerQuery.builder() | ||
.onlyOrgId(onlyOrgId); | ||
|
||
for (final BPartnerCompositeLookupKey bpartnerLookupKey : bpartnerLookupKeys) | ||
{ | ||
addKeyToQueryBuilder(bpartnerLookupKey, query); | ||
} | ||
|
||
return query.build(); | ||
} | ||
|
||
private static void addKeyToQueryBuilder(final BPartnerCompositeLookupKey bpartnerLookupKey, final BPartnerQuery.BPartnerQueryBuilder queryBuilder) | ||
{ | ||
final JsonExternalId jsonExternalId = bpartnerLookupKey.getJsonExternalId(); | ||
if (jsonExternalId != null) | ||
{ | ||
queryBuilder.externalId(JsonConverters.fromJsonOrNull(jsonExternalId)); | ||
} | ||
|
||
final String value = bpartnerLookupKey.getCode(); | ||
if (!isEmpty(value, true)) | ||
{ | ||
queryBuilder.bpartnerValue(value); | ||
} | ||
|
||
final GLN gln = bpartnerLookupKey.getGln(); | ||
if (gln != null) | ||
{ | ||
queryBuilder.gln(gln); | ||
} | ||
|
||
final MetasfreshId metasfreshId = bpartnerLookupKey.getMetasfreshId(); | ||
if (metasfreshId != null) | ||
{ | ||
queryBuilder.bPartnerId(BPartnerId.ofRepoId(metasfreshId.getValue())); | ||
} | ||
} | ||
|
||
} |
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